FAQ
i have written code on linux for parsing text files and it works great
but when i try to run it on windows it goes crazy, do you have any
idea???

Search Discussions

  • Irmen de Jong at Jul 3, 2011 at 11:47 pm

    On 4-7-2011 1:41, amir chaouki wrote:
    i have written code on linux for parsing text files and it works great
    but when i try to run it on windows it goes crazy, do you have any
    idea???
    No, I misplaced my crystal ball.

    Irmen


    P.S. http://www.catb.org/~esr/faqs/smart-questions.html
  • TheSaint at Jul 4, 2011 at 7:16 am

    Irmen de Jong wrote:

    No, I misplaced my crystal ball.
    I'm waiting mine, brand new in HD :D, with remote control :D :D

    --
    goto /dev/null
  • Gregory Ewing at Jul 4, 2011 at 8:48 am

    TheSaint wrote:
    On 4-7-2011 1:41, amir chaouki wrote:

    No, I misplaced my crystal ball.
    I'm waiting mine, brand new in HD :D, with remote control :D :D
    The new digital models are great. But there's a
    distressing tendency for visions to come with
    DRM protection these days, so you can only share
    them with at most 5 other users. :-(

    --
    Greg
  • Dan Stromberg at Jul 3, 2011 at 11:54 pm
    You'll probably want to give more detail about what your code is doing and
    what it should be doing. Mindreading is hard, especially when it's
    accurate.

    Usually the main difference between *ix and windows for text files is the
    line endings though - on *ix, you can open a file as text or binary, and
    things are the same. On windows, you need to read a text file as 'r' and a
    binary file as 'rb'.

    See also dos2unix and unix2dos.

    BTW, are you using a native windows python, or a cygwin python? Are you
    using python 2.x or 3.x? CPython, PyPy, Jython, Pyjamas, IronPython...?
    On Sun, Jul 3, 2011 at 4:41 PM, amir chaouki wrote:

    i have written code on linux for parsing text files and it works great
    but when i try to run it on windows it goes crazy, do you have any
    idea???
    --
    http://mail.python.org/mailman/listinfo/python-list
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20110703/8a5e0615/attachment.html>
  • Rantingrick at Jul 3, 2011 at 11:54 pm

    On Jul 3, 6:41?pm, amir chaouki wrote:
    i have written code on linux for parsing text files and it works great
    but when i try to run it on windows it goes crazy, do you have any
    idea???
    psst: you should show us the code first. :)
  • Chris Angelico at Jul 3, 2011 at 11:54 pm

    On Mon, Jul 4, 2011 at 9:41 AM, amir chaouki wrote:
    i have written code on linux for parsing text files and it works great
    but when i try to run it on windows it goes crazy, do you have any
    idea???
    If you share your code, we may be able to help. Alternatively, here's
    a few differences to look at:

    1) Filenames - if you have a literal for your file name,
    "/home/foobar/file" will work, but "c:\path\newfile.txt" won't -
    backslash is a special character. Make it a raw string:
    r"c:\path\newfile.txt" - that will work.

    2) End of line characters. If you divide the contents of the file on
    the "\n" character, and then try to work with the end of each line,
    you may find that the string has a "\r" character at the end.

    3) What Irmen de Jong said. :)

    Chris Angelico
  • Amir chaouki at Jul 3, 2011 at 11:58 pm
    the problem is when i use the seek function on windows it gives me
    false results other then the results on *ux. the file that i work with
    are very large about 10mb.
  • Steven D'Aprano at Jul 4, 2011 at 11:30 pm

    amir chaouki wrote:

    the problem is when i use the seek function on windows it gives me
    false results
    What do you mean "false results"? What does this even mean?

    Please show us:

    * what you do
    * what result you expect
    * what result you actually get



    --
    Steven
  • Dan Stromberg at Jul 5, 2011 at 12:09 am
    It turned out that switching to binary I/O made seek do what he was
    expecting. I'm guessing the transparent crlf to lf conversions in windows
    text I/O get seek() a bit perplexed, because it transparently changes the
    number of bytes.
    On Mon, Jul 4, 2011 at 4:30 PM, Steven D'Aprano wrote:

    amir chaouki wrote:
    the problem is when i use the seek function on windows it gives me
    false results
    What do you mean "false results"? What does this even mean?

    Please show us:

    * what you do
    * what result you expect
    * what result you actually get



    --
    Steven

    --
    http://mail.python.org/mailman/listinfo/python-list
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20110704/fa4f9353/attachment.html>
  • Dave Angel at Jul 5, 2011 at 2:26 am

    On 01/-10/-28163 02:59 PM, amir chaouki wrote:
    the problem is when i use the seek function on windows it gives me
    false results other then the results on *ux. the file that i work with
    are very large about 10mb.
    If you still care about this problem, you should take some of the other
    suggestions to heart; post some code, state what you expected, and what
    actually happened, and how they're different.

    But my crystal ball says you're trying to do a seek on a text file,
    which has restrictions. Once you've called it a text file, you're
    telling the system to translate cr/lf pairs into lf, which changes the
    apparent size. So seek has no way to reproduce what reading lines does.


    To quote the docs at http://docs.python.org/library/stdtypes.html :
    "If the file is opened in text mode (without 'b'), only offsets returned
    by tell() <http://docs.python.org/library/stdtypes.html#file.tell> are
    legal. Use of other offsets causes undefined behavior."

    DaveA
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20110704/7f58dc8b/attachment.html>
  • Nobody at Jul 5, 2011 at 8:14 am

    On Sun, 03 Jul 2011 16:58:24 -0700, amir chaouki wrote:

    the problem is when i use the seek function on windows it gives me
    false results other then the results on *ux. the file that i work with
    are very large about 10mb.
    This is probably an issue with how the underlying C functions behave on
    Windows, related to the CRLF<->LF conversions when a file is opened in
    text mode.

    The Python library documention for the .seek() method says:
    If the file is opened in text mode (without 'b'), only offsets returned
    by tell() are legal. Use of other offsets causes undefined behavior.
    IOW, you can't use computed offsets with files opened in text mode
    (although in practice this will work for platforms other than Windows). If
    you want to use computed offsets, open the file in binary mode and strip
    the trailing CRs yourself.

    And 10MB isn't "very large"; it's not even "large". You normally only
    start running into problems with files which are 2GiB (2,147,483,648
    bytes) or more (i.e. if you can't fit the size into a signed 32-bit
    integer).
  • Ben Finney at Jul 4, 2011 at 12:12 am

    amir chaouki <chaouki.amir at gmail.com> writes:

    i have written code on linux for parsing text files and it works great
    but when i try to run it on windows it goes crazy, do you have any
    idea???
    Please compose a new message, with a descriptive ?Subject? field,
    example code that we can run, and your expectations for what the code
    should do.

    --
    \ ?In general my children refuse to eat anything that hasn't |
    `\ danced on television.? ?Erma Bombeck |
    _o__) |
    Ben Finney
  • Grant Edwards at Jul 4, 2011 at 12:34 am

    On 2011-07-03, amir chaouki wrote:

    i have written code on linux for parsing text files and it works great
    but when i try to run it on windows it goes crazy, do you have any
    idea???
    Yes.

    --
    Grant Edwards grant.b.edwards Yow! LOOK!! Sullen
    at American teens wearing
    gmail.com MADRAS shorts and "Flock of
    Seagulls" HAIRCUTS!
  • Milosh zorica at Jul 4, 2011 at 12:57 am
    filenames and the crlf / eof thing come to my mind first

    linux and windows handle files all different


    On Sun, Jul 3, 2011 at 9:34 PM, Grant Edwards wrote:
    On 2011-07-03, amir chaouki wrote:

    i have written code on linux for parsing text files and it works great
    but when i try to run it on windows it goes crazy, do you have any
    idea???
    Yes.

    --
    Grant Edwards ? ? ? ? ? ? ? grant.b.edwards ? ? ? ?Yow! LOOK!! ?Sullen
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?at ? ? ? ? ? ? ? American teens wearing
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?gmail.com ? ? ? ? ? ?MADRAS shorts and "Flock of
    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Seagulls" HAIRCUTS!
    --
    http://mail.python.org/mailman/listinfo/python-list


    --
    Milosh Zorica
    http://www.linkedin.com/in/miloshzorica | www.coroflot.com/miloshz

    http://tangoinabox.co.uk
    Tango in a Box - Online Media Production, the Tango Principles Applied -
    Born in Argentina, Growing up Globally

    +1 310 601 4396 | +44 20 8144 5294 | +54 9 11 3515 7187

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJul 3, '11 at 11:41p
activeJul 5, '11 at 8:14a
posts15
users13
websitepython.org

People

Translate

site design / logo © 2022 Grokbase