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

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 w

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

Reading/Writing files

2011-03-18 Thread Jon Herman
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 (where I import modules f

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 == "": >

Reading, writing files

2009-08-21 Thread seanm
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 == "": break f2.write(text) f1.close() f2.close()

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

reading/writing files

2007-11-27 Thread sandipm
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 types, its failing. actually main problem is i am uploading file using cgi, in this process I am getting content of file, and I am trying to save the file. I

Re: remove header line when reading/writing files

2007-10-11 Thread Marc 'BlackJack' Rintsch
On Thu, 11 Oct 2007 22:52:55 +, RyanL wrote: > I'm a newbie with a large number of data files in multiple > directories. I want to uncompress, read, and copy the contents of > each file into one master data file. The code below seems to be doing > this perfectly. The problem is each of the

Re: remove header line when reading/writing files

2007-10-11 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > ... > for zipfile in filelist: > zfiter = iter(gzip.Gzipfile(zipfile,'r')) > zfiter.next() # ignore header line > for i, line in enumerate(fziter): > outfile.write(line) Or even: writes = outfile.write for zipfile in filelist: zfiter = it

Re: remove header line when reading/writing files

2007-10-11 Thread timaranz
On Oct 12, 12:23 pm, Tim Chase <[EMAIL PROTECTED]> wrote: > Forgot the enumerate call of all things > > > for zipfile in filelist: > >for i, line in enumerate(gzip.Gzipfile(zipfile,'r')): > >if i: outfile.write(line) > > Some days, I'm braindead. > > -tkc I would move the 'if' test

Re: remove header line when reading/writing files

2007-10-11 Thread Tim Chase
Forgot the enumerate call of all things > for zipfile in filelist: > for i, line in enumerate(gzip.Gzipfile(zipfile,'r')): > if i: outfile.write(line) Some days, I'm braindead. -tkc -- http://mail.python.org/mailman/listinfo/python-list

Re: remove header line when reading/writing files

2007-10-11 Thread Tim Chase
> each file into one master data file. The code below seems to be doing > this perfectly. The problem is each of the data files has a header > row in the first line, which I do not want in the master file. How > can I skip that first line when writing to the master file? Any help > is much appr

remove header line when reading/writing files

2007-10-11 Thread RyanL
I'm a newbie with a large number of data files in multiple directories. I want to uncompress, read, and copy the contents of each file into one master data file. The code below seems to be doing this perfectly. The problem is each of the data files has a header row in the first line, which I do

Re: Problem reading/writing files

2006-08-04 Thread Roel Schroeven
[EMAIL PROTECTED] schreef: > Well, now I tried running the script and it worked fine with the .gfx > file. Originally I was working using the IDLE, which I wouldn't have > thought would make a difference, but when I ran the script on its own > it worked fine and when I ran it in the IDLE it didn't

Re: Problem reading/writing files

2006-08-04 Thread smeenehan
Well, now I tried running the script and it worked fine with the .gfx file. Originally I was working using the IDLE, which I wouldn't have thought would make a difference, but when I ran the script on its own it worked fine and when I ran it in the IDLE it didn't work unless the data was in a text

Re: Problem reading/writing files

2006-08-04 Thread Roel Schroeven
[EMAIL PROTECTED] schreef: > f = open('evil2.gfx','rb') > i1 = open('img1.jpg','wb') > i2 = open('img2.png','wb') > i3 = open('img3.gif','wb') > i4 = open('img4.png','wb') > i5 = open('img5.jpg','wb') > > > for i in range(0,67575,5): > i1.write(f.read(1)) > i2.write(f.read(1)) > i3.wr

Re: Problem reading/writing files

2006-08-04 Thread smeenehan
Ok, now I'm very confused, even though I just solved my problem. I copied the entire contents of the original file (evil2.gfx) from my hex editor and pasted it into a text file. When I read from *this* file using my original code, everything worked fine. When I read the 21st byte, it came up as the

Re: Problem reading/writing files

2006-08-04 Thread smeenehan
> What platform? What version of Python? Have you opened the > file in binary mode i.e. open('thefile', 'rb') ?? Show us the relevant > parts of your code, plus what caused you to conclude that read() > changed data on the fly in an undocumented fashion. Yes, I've been reading and writing everyt

Re: Problem reading/writing files

2006-08-03 Thread John Machin
[EMAIL PROTECTED] wrote: > This is a bit of a peculiar problem. First off, this relates to Python > Challenge #12, so if you are attempting those and have yet to finish > #12, as there are potential spoilers here. > > I have five different image files shuffled up in one big binary file. > In order

Re: Problem reading/writing files

2006-08-03 Thread Simon Forman
[EMAIL PROTECTED] wrote: > This is a bit of a peculiar problem. First off, this relates to Python > Challenge #12, so if you are attempting those and have yet to finish > #12, as there are potential spoilers here. > > I have five different image files shuffled up in one big binary file. > In order

Re: Problem reading/writing files

2006-08-03 Thread faulkner
have you been using text mode? [EMAIL PROTECTED] wrote: > This is a bit of a peculiar problem. First off, this relates to Python > Challenge #12, so if you are attempting those and have yet to finish > #12, as there are potential spoilers here. > > I have five different image files shuffled up in

Problem reading/writing files

2006-08-03 Thread smeenehan
This is a bit of a peculiar problem. First off, this relates to Python Challenge #12, so if you are attempting those and have yet to finish #12, as there are potential spoilers here. I have five different image files shuffled up in one big binary file. In order to view them I have to "unshuffle" t