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 et...@stoneleaf.us mailto:et...@stoneleaf.us wrote: Dan Stromberg wrote: Are you on windows? You probably should use / as your directory separator in Python, not \. In

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 et...@stoneleaf.us mailto:et...@stoneleaf.us wrote: Dan Stromberg wrote: Are you on windows? You probably should

Re: Reading/Writing files

2011-03-25 Thread Dan Stromberg
On Fri, Mar 25, 2011 at 6:42 AM, Westley Martínez aniko...@gmail.comwrote: 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

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 convention

Re: Reading/Writing files

2011-03-19 Thread Dan Stromberg
On Sat, Mar 19, 2011 at 12:55 AM, Nobody nob...@nowhere.com 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

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

Re: Reading/Writing files

2011-03-18 Thread Jack Trades
On Fri, Mar 18, 2011 at 4:33 PM, Jon Herman jfc.her...@gmail.com 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.

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

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: [Errno

Re: Reading/Writing files

2011-03-18 Thread Jack Trades
On Fri, Mar 18, 2011 at 4:56 PM, Jon Herman jfc.her...@gmail.com 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

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:,

Re: Reading/Writing files

2011-03-18 Thread Jack Trades
On Fri, Mar 18, 2011 at 4:59 PM, Jack Trades jacktradespub...@gmail.comwrote: On Fri, Mar 18, 2011 at 4:56 PM, Jon Herman jfc.her...@gmail.com 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:

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 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

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

Re: Reading/Writing files

2011-03-18 Thread Jack Trades
On Fri, Mar 18, 2011 at 5:21 PM, Jon Herman jfc.her...@gmail.com 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

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 my

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

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? badadvice / 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 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 jacktradespub...@gmail.comwrote: On Fri, Mar 18, 2011 at 5:21

Re: Reading/Writing files

2011-03-18 Thread Dan Stromberg
On Fri, Mar 18, 2011 at 4:00 PM, Ethan Furman 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 programming languages, \ starts an escape sequence, so to introduce a literal

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

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

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 other mime

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