Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #87062 > unrolled thread

Append a file

Started byJason Venneri <jv92109@gmail.com>
First post2015-03-06 13:55 -0800
Last post2015-03-08 22:11 -0700
Articles 4 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Append a file Jason Venneri <jv92109@gmail.com> - 2015-03-06 13:55 -0800
    Re: Append a file sohcahtoa82@gmail.com - 2015-03-06 14:05 -0800
    Re: Append a file Jason Friedman <jsf80238@gmail.com> - 2015-03-06 22:37 -0700
    Re: Append a file Jason Venneri <jven2eri@gmail.com> - 2015-03-08 22:11 -0700

#87062 — Append a file

FromJason Venneri <jv92109@gmail.com>
Date2015-03-06 13:55 -0800
SubjectAppend a file
Message-ID<adcd6103-cba5-4eda-9af6-e6ba95789159@googlegroups.com>
Hello, I'm using the urllib.urlretrieve command to retrieve a couple of lines of data.  I want to combine the two results into one file not two.  

Any suggestions?

Sample
urllib.urlretrieve('http://www.airplanes.com/data/boeing1.html','B747A.txt')
urllib.urlretrieve('http://www.airplanes.com/data/boeing2.html','B747B.txt')

I would like one file say B747C that contains the data from B747A and B747B in a file named B747C

[toc] | [next] | [standalone]


#87063

Fromsohcahtoa82@gmail.com
Date2015-03-06 14:05 -0800
Message-ID<53fba4b4-d751-4e57-9da3-7fa1aa3ed8f1@googlegroups.com>
In reply to#87062
On Friday, March 6, 2015 at 1:55:31 PM UTC-8, Jason Venneri wrote:
> Hello, I'm using the urllib.urlretrieve command to retrieve a couple of lines of data.  I want to combine the two results into one file not two.  
> 
> Any suggestions?
> 
> Sample
> urllib.urlretrieve('http://www.airplanes.com/data/boeing1.html','B747A.txt')
> urllib.urlretrieve('http://www.airplanes.com/data/boeing2.html','B747B.txt')
> 
> I would like one file say B747C that contains the data from B747A and B747B in a file named B747C

What have you tried so far?  Generally on this mailing list, we'll help you find what you're doing wrong, but we won't write your script for you.

I'll give you one hint though, you should probably try urllib.urlopen, then write the file yourself.

[toc] | [prev] | [next] | [standalone]


#87075

FromJason Friedman <jsf80238@gmail.com>
Date2015-03-06 22:37 -0700
Message-ID<mailman.131.1425706640.21433.python-list@python.org>
In reply to#87062
On Fri, Mar 6, 2015 at 2:55 PM, Jason Venneri <jv92109@gmail.com> wrote:
> Hello, I'm using the urllib.urlretrieve command to retrieve a couple of lines of data.  I want to combine the two results into one file not two.
>
> Any suggestions?
>
> Sample
> urllib.urlretrieve('http://www.airplanes.com/data/boeing1.html','B747A.txt')
> urllib.urlretrieve('http://www.airplanes.com/data/boeing2.html','B747B.txt')
>
> I would like one file say B747C that contains the data from B747A and B747B in a file named B747C

>>> f = open("B747C.txt", "w")
>>> look_for = "Aircraft,"
>>> for line in open("B747A.txt"):
...     if look_for in line:
...         f.write(line)
...
>>> for line in open("B747B.txt"):
...     if look_for in line:
...         f.write(line)
...
>>> f.close()

Seems like you are using Python 2, you ought to consider Python 3.

The requests module
(http://docs.python-requests.org/en/latest/user/install/) makes this
kind of work easier.

[toc] | [prev] | [next] | [standalone]


#87172

FromJason Venneri <jven2eri@gmail.com>
Date2015-03-08 22:11 -0700
Message-ID<mailman.185.1425877880.21433.python-list@python.org>
In reply to#87062
Jason;

Thank you for your response.  I’m just starting out with Python and the tutorials I have done are on 2.7.9.  I will looking on to python3.  It is preloaded on Mac :-).

Jason
_______________________________


jv92109@gmail.com

619-227-0927

> On Mar 6, 2015, at 9:37 PM, Jason Friedman <jsf80238@gmail.com> wrote:
> 
> On Fri, Mar 6, 2015 at 2:55 PM, Jason Venneri <jv92109@gmail.com> wrote:
>> Hello, I'm using the urllib.urlretrieve command to retrieve a couple of lines of data.  I want to combine the two results into one file not two.
>> 
>> Any suggestions?
>> 
>> Sample
>> urllib.urlretrieve('http://www.airplanes.com/data/boeing1.html','B747A.txt')
>> urllib.urlretrieve('http://www.airplanes.com/data/boeing2.html','B747B.txt')
>> 
>> I would like one file say B747C that contains the data from B747A and B747B in a file named B747C
> 
>>>> f = open("B747C.txt", "w")
>>>> look_for = "Aircraft,"
>>>> for line in open("B747A.txt"):
> ...     if look_for in line:
> ...         f.write(line)
> ...
>>>> for line in open("B747B.txt"):
> ...     if look_for in line:
> ...         f.write(line)
> ...
>>>> f.close()
> 
> Seems like you are using Python 2, you ought to consider Python 3.
> 
> The requests module
> (http://docs.python-requests.org/en/latest/user/install/) makes this
> kind of work easier.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web