Re: Reading/Writing files

2011-03-25 Thread Dan Stromberg
On Fri, Mar 25, 2011 at 6:42 AM, Westley Martínez wrote: > > > > I argue that the first is quite a bit more readable than the second: > > > 'c:/temp/choose_python.pdf' > > > os.path.join([ 'c:', 'temp', 'choose_python.pdf' ]) > > > > I agree with your argument, but think that > > r'c:\tem

Re: Reading/Writing files

2011-03-25 Thread Westley Martínez
On Fri, 2011-03-25 at 05:39 -0700, Ethan Furman wrote: > On 3/18/2011 6:25 PM, Dan Stromberg wrote: > > > > On Fri, Mar 18, 2011 at 4:00 PM, Ethan Furman > > wrote: > > > > Dan Stromberg wrote: > > > > > > Are you on windows? > > > > You probably shou

Re: Reading/Writing files

2011-03-25 Thread Ethan Furman
On 3/18/2011 6:25 PM, Dan Stromberg wrote: On Fri, Mar 18, 2011 at 4:00 PM, Ethan Furman mailto:et...@stoneleaf.us>> wrote: Dan Stromberg wrote: Are you on windows? You probably should use / as your directory separator in Python, not \. In Python, and most other

Re: Reading/Writing files

2011-03-19 Thread Dan Stromberg
On Sat, Mar 19, 2011 at 12:55 AM, Nobody wrote: > On Fri, 18 Mar 2011 16:00:55 -0700, Ethan Furman wrote: > > Dan Stromberg wrote: > > > / works fine on windows, and doesn't require escaping ("/foo/bar"). > > "/" works fine in most contexts, but not in shell commands, where "/" is > conventionall

Re: Reading/Writing files

2011-03-19 Thread Nobody
On Fri, 18 Mar 2011 16:00:55 -0700, Ethan Furman wrote: Dan Stromberg wrote: > / works fine on windows, and doesn't require escaping ("/foo/bar"). "/" works fine in most contexts, but not in shell commands, where "/" is conventionally used to indicate a switch. Commands which follow this convent

Re: Reading/Writing files

2011-03-18 Thread Dan Stromberg
On Fri, Mar 18, 2011 at 4:00 PM, Ethan Furman wrote: > Dan Stromberg wrote: > >> >> Are you on windows? >> >> You probably should use / as your directory separator in Python, not \. >> In Python, and most other programming languages, \ starts an escape >> sequence, so to introduce a literal \, y

Re: Reading/Writing files

2011-03-18 Thread Jon Herman
Wow, Jack, that is one awesome and simple module...thank you so much! I am happily storing and accessing all the arrays I could ever want :) Thanks to all for the quick assistance! On Fri, Mar 18, 2011 at 4:24 PM, Jack Trades wrote: > > On Fri, Mar 18, 2011 at 5:21 PM, Jon Herman wrote: > >>

Re: Reading/Writing files

2011-03-18 Thread Westley Martínez
On Fri, 2011-03-18 at 15:18 -0700, Dan Stromberg wrote: > > Are you on windows? > > You shouldn't use / or \ on Windows. You should use os.path.join(). On Windows, when you start mixing / with \\ and spaces things can get hairy and obscure. It's always best to just use os.path.join(). -

Re: Reading/Writing files

2011-03-18 Thread Ethan Furman
Dan Stromberg wrote: Are you on windows? You probably should use / as your directory separator in Python, not \. In Python, and most other programming languages, \ starts an escape sequence, so to introduce a literal \, you either need to prefix your string with r (r"\foo\bar") or double yo

Re: Reading/Writing files

2011-03-18 Thread Westley Martínez
On Fri, 2011-03-18 at 15:56 -0600, Jon Herman wrote: > Jack, > > thanks. > > Alright, so what I did is create a file called hello.txt with a single > line of text in there. I then did the following: > > f="fulldirectory\hello.txt" (where fulldirectory is of course the > actual full directory on

Re: Reading/Writing files

2011-03-18 Thread Jack Trades
On Fri, Mar 18, 2011 at 5:21 PM, Jon Herman wrote: > Folks, > > thanks for the many responses! Specifying the full file name (and not using > parentheses when inappropriate, thanks Jack :)) I am now happily > reading/writing files. > > My next question: what is the best way for me to write an arr

Re: Reading/Writing files

2011-03-18 Thread Jon Herman
Folks, thanks for the many responses! Specifying the full file name (and not using parentheses when inappropriate, thanks Jack :)) I am now happily reading/writing files. My next question: what is the best way for me to write an array I generated to a file? And what is the best way for me to load

Re: Reading/Writing files

2011-03-18 Thread Alexander Kapps
On 18.03.2011 22:33, Jon Herman wrote: Hello all, I am pretty new to Python and am trying to write data to a file. However, I seem to be misunderstanding how to do so. For starters, I'm not even sure where Python is looking for these files or storing them. The directories I have added to my PYTH

Re: Reading/Writing files

2011-03-18 Thread Dan Stromberg
Are you on windows? You probably should use / as your directory separator in Python, not \. In Python, and most other programming languages, \ starts an escape sequence, so to introduce a literal \, you either need to prefix your string with r (r"\foo\bar") or double your backslashes ("\\foo\\bar

Re: Reading/Writing files

2011-03-18 Thread Jack Trades
On Fri, Mar 18, 2011 at 4:59 PM, Jack Trades wrote: > > > On Fri, Mar 18, 2011 at 4:56 PM, Jon Herman wrote: > >> Jack, >> >> thanks. >> >> Alright, so what I did is create a file called hello.txt with a single >> line of text in there. I then did the following: >> >> f="fulldirectory\hello.txt"

Re: Reading/Writing files

2011-03-18 Thread Dan Stromberg
For open() or os.open(), it should look in your Current Working Directory (CWD). Your python's CWD defaults to what the CWD was when python was started, and it is changed with os.chdir(). Absolute paths will of course be relative to / on most OS's (or C:/ if you're on C:, D:/ if you're on D:, etc

Re: Reading/Writing files

2011-03-18 Thread Jack Trades
On Fri, Mar 18, 2011 at 4:56 PM, Jon Herman wrote: > Jack, > > thanks. > > Alright, so what I did is create a file called hello.txt with a single line > of text in there. I then did the following: > > f="fulldirectory\hello.txt" (where fulldirectory is of course the actual > full directory on my

Re: Reading/Writing files

2011-03-18 Thread Jon Herman
Jack, thanks. Alright, so what I did is create a file called hello.txt with a single line of text in there. I then did the following: f="fulldirectory\hello.txt" (where fulldirectory is of course the actual full directory on my computer) open("f", "w") And I get the following error: IOError: [E

Re: Reading/Writing files

2011-03-18 Thread Ethan Furman
Jon Herman wrote: Hello all, I am pretty new to Python and am trying to write data to a file. However, I seem to be misunderstanding how to do so. For starters, I'm not even sure where Python is looking for these files or storing them. The directories I have added to my PYTHONPATH variable (w

Re: Reading/Writing files

2011-03-18 Thread Jack Trades
On Fri, Mar 18, 2011 at 4:33 PM, Jon Herman wrote: > Hello all, > > I am pretty new to Python and am trying to write data to a file. However, I > seem to be misunderstanding how to do so. For starters, I'm not even sure > where Python is looking for these files or storing them. The directories I

Re: Reading/Writing files

2011-03-18 Thread Matt Chaput
On 18/03/2011 5:33 PM, Jon Herman wrote: I am pretty new to Python and am trying to write data to a file. However, I seem to be misunderstanding how to do so. For starters, I'm not even sure where Python is looking for these files or storing them. The directories I have added to my PYTHONPATH var

Re: Reading, writing files

2009-08-21 Thread MRAB
seanm wrote: In the book I am using, they give the following function as an example: def copyFile(oldFile, newFile): f1 = open(oldFile, 'r') f2 = open(newFile, 'w') while True: text = f1.read(50) This will read up to 50 characters from the input file. At the end of the file

Re: Reading, writing files

2009-08-21 Thread Albert Hopkins
On Fri, 2009-08-21 at 15:21 -0700, seanm wrote: > In the book I am using, they give the following function as an > example: > > def copyFile(oldFile, newFile): > f1 = open(oldFile, 'r') > f2 = open(newFile, 'w') > while True: > text = f1.read(50) > if text == "": >

Re: reading/writing files

2007-11-27 Thread BartlebyScrivener
On Nov 27, 7:14 am, sandipm <[EMAIL PROTECTED]> wrote: > f1= open("file1.pdf", "rb") > x = f1.read() > open("file2.pdf", "wb").write(x) > > works... > > thanks > sandip You might also like: http://pybrary.net/pyPdf/ -- http://mail.python.org/mailman/listinfo/python-list

Re: reading/writing files

2007-11-27 Thread sandipm
f1= open("file1.pdf", "rb") x = f1.read() open("file2.pdf", "wb").write(x) works... thanks sandip On Nov 27, 5:43 pm, sandipm <[EMAIL PROTECTED]> wrote: > Hi, > > I am trying to read a file and write into other file. if I do it for > simple text file, it works well. > but for pdfs or some ot