[Tutor] P4Python silent Installation

2012-01-25 Thread Nitish Mahajan
Hi,


I use Python 2.5 and hence consequently use the file
P4Python-1.0.win32-py2.5.exe in order to add the Perforce APIs. I would
like to create a silent installation for them.

Python 2.5 being an msi is easily run silently using /q but the other file
“P4Python-1.0.win32-py2.5.exe” doesnot accept that flag. It says that it is
created using “Distutils-2.5.0”.

Is there any standard flag for silent installation for disutils file. Else
is there a way I can create an msi package of this file
“P4Python-1.0.win32-py2.5.exe” on which I can use the flag.



*Regards*,
Nitish
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] P4Python silent Installation

2012-01-25 Thread Steven D'Aprano

Nitish Mahajan wrote:


I use Python 2.5 and hence consequently use the file
P4Python-1.0.win32-py2.5.exe in order to add the Perforce APIs. I would
like to create a silent installation for them.



Hello Nitish,

This mailing list is for people interested in learning the language Python, 
not for arbitrary questions related to Python programming. Questions about 
writing silent installers using distutils are a bit too specialised for this list.


You might be lucky to find somebody who is expect on distutils here, but you 
are probably better off asking on a specialist distutils mailing list (if 
there is one) or perhaps the generic Python newsgroup comp.lang.python (also 
available as a mailing list, python-l...@python.org).


Good luck!




--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to read and write to a file

2012-01-25 Thread ken brockman
I would like to write to and read from a file from python. I wanted to use the 
file to save input to the program in a list. I have been looking around and 
there seems to be several ways to go about it. I tried pickling, but am having 
an issue with it. What would be the correct way to accomplish this? I have 
tried several ways, but to no avail. I get no error msg. but the list isn't 
retaining the info. Is pickling even the best way to do it.

file1 = open("ArtyKlikes.p", "ab")  # likesList
file2 = open("ArtyDislikes.p", "ab")  # dislikes

pickle.dump(likesList, file1)
pickle.dump(dislikeList, file2)

file1.close()
file2.close()

Any help would be greatly appreciated.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to read and write to a file

2012-01-25 Thread Alexander
On Wed, Jan 25, 2012 at 7:19 AM, ken brockman  wrote:

> I would like to write to and read from a file from python. I wanted to use
> the file to save input to the program in a list. I have been looking around
> and there seems to be several ways to go about it. I tried pickling, but am
> having an issue with it. What would be the correct way to accomplish this?
> I have tried several ways, but to no avail. I get no error msg. but the
> list isn't retaining the info. Is pickling even the best way to do it.
>
> file1 = open("ArtyKlikes.p", "ab")  # likesList
> file2 = open("ArtyDislikes.p", "ab")  # dislikes
>
> pickle.dump(likesList, file1)
> pickle.dump(dislikeList, file2)
>
> file1.close()
> file2.close()
>
> Any help would be greatly appreciated.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
Hi Ken. If you just want to read and write from a text file then you don't
need to pickle.
For example,
(the file info.txt exists)

>>>fh = open ( 'info.txt', 'w' )
>>>fh.write ( 'peter piper picked a pack of pickled peppers.' )
>>>fh.close()
>>>fr = open ( 'info.txt', 'r')
>>>fr.readline()
'peter piper picked a pack of pickled peppers.'
>>>fr.close()

or whatever.
But do you have a need to use pickling?
-- 
Alexander
7D9C597B
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to read and write to a file

2012-01-25 Thread Alexander
On Wed, Jan 25, 2012 at 8:32 AM, ken brockman  wrote:
>
>
> 
> From: Alexander 
> To: ken brockman 
> Cc: "tutor@python.org" 
> Sent: Wednesday, January 25, 2012 7:38 AM
> Subject: Re: [Tutor] how to read and write to a file
>
>
>
> On Wed, Jan 25, 2012 at 7:19 AM, ken brockman  wrote:
>
> I would like to write to and read from a file from python. I wanted to use 
> the file to save input to the program in a list. I have been looking around 
> and there seems to be several ways to go about it. I tried pickling, but am 
> having an issue with it. What would be the correct way to accomplish this? I 
> have tried several ways, but to no avail. I get no error msg. but the list 
> isn't retaining the info. Is pickling even the best way to do it.
>
> file1 = open("ArtyKlikes.p", "ab")  # likesList
> file2 = open("ArtyDislikes.p", "ab")  # dislikes
>
> pickle.dump(likesList, file1)
> pickle.dump(dislikeList, file2)
>
> file1.close()
> file2.close()
>
> Any help would be greatly appreciated.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
> Hi Ken. If you just want to read and write from a text file then you don't 
> need to pickle.
> For example,
> (the file info.txt exists)
>
> >>>fh = open ( 'info.txt', 'w' )
> >>>fh.write ( 'peter piper picked a pack of pickled peppers.' )
> >>>fh.close()
> >>>fr = open ( 'info.txt', 'r')
> >>>fr.readline()
> 'peter piper picked a pack of pickled peppers.'
> >>>fr.close()
>
> or whatever.
> But do you have a need to use pickling?
> --
> Alexander
> 7D9C597B
> --
>
> Hey Alexander,
> I had to try it before I went to sleep.
> No good. I got an error msg. TypeError: must be str, not list.
> So I guess that may be why i had went with pickling. I needed something that 
> would work with a list. Unless there is some other way?
> Thanks again for taking the time to help out.
>
> Ken
>
>
Ken, pickling is used when one wants to send information through a
network or communicate with a database. Somebody else here knows more
about pickling than I do. As for your list problem... I'm not exactly
certain what you're trying to do. But I'm going with the idea that you
have two files of information, one contains strings you like, and the
other contains strings you dislike. And you want to read and write
this information using Python.

>>> like = [ 'orange', 'blue', 'red' ] #things I like
>>> dislike = [ 'apples', 'bronze', 'bananas' ] #things I dislike
>>> fh = open ( 'likes.txt', 'w' ) #let's open a file stream to write

# fh is my shorthand for "file handle"
#writing a list to a file stream:

>>> for index in range( len( like )):
fh.write( like[ index ] )
fh.write ( '\n' ) #here i add a new line, maybe somebody else
#knows a better way to avoid this?

>>> fh.close()

#now let's read that information into a list
>>> fr = open ( 'info.txt' ) #I'm using python 3.2
>>> mylistoflikes = fr.readlines()
>>> mylistoflikes
[ 'orange\n' , 'blue\n' , 'red\n' ]
>>> fr.close()

--
Alexander
7D9C597B
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to read and write to a file

2012-01-25 Thread Joel Goldstick
On Wed, Jan 25, 2012 at 9:14 AM, Alexander  wrote:
> On Wed, Jan 25, 2012 at 8:32 AM, ken brockman  wrote:
>>
>>
>> 
>> From: Alexander 
>> To: ken brockman 
>> Cc: "tutor@python.org" 
>> Sent: Wednesday, January 25, 2012 7:38 AM
>> Subject: Re: [Tutor] how to read and write to a file
>>
>>
>>
>> On Wed, Jan 25, 2012 at 7:19 AM, ken brockman  wrote:
>>
>> I would like to write to and read from a file from python. I wanted to use 
>> the file to save input to the program in a list. I have been looking around 
>> and there seems to be several ways to go about it. I tried pickling, but am 
>> having an issue with it. What would be the correct way to accomplish this? I 
>> have tried several ways, but to no avail. I get no error msg. but the list 
>> isn't retaining the info. Is pickling even the best way to do it.
>>
>> file1 = open("ArtyKlikes.p", "ab")  # likesList
>> file2 = open("ArtyDislikes.p", "ab")  # dislikes
>>
>> pickle.dump(likesList, file1)
>> pickle.dump(dislikeList, file2)
>>
>> file1.close()
>> file2.close()
>>
>> Any help would be greatly appreciated.
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>> Hi Ken. If you just want to read and write from a text file then you don't 
>> need to pickle.
>> For example,
>> (the file info.txt exists)
>>
>> >>>fh = open ( 'info.txt', 'w' )
>> >>>fh.write ( 'peter piper picked a pack of pickled peppers.' )
>> >>>fh.close()
>> >>>fr = open ( 'info.txt', 'r')
>> >>>fr.readline()
>> 'peter piper picked a pack of pickled peppers.'
>> >>>fr.close()
>>
>> or whatever.
>> But do you have a need to use pickling?
>> --
>> Alexander
>> 7D9C597B
>> --
>>
>> Hey Alexander,
>> I had to try it before I went to sleep.
>> No good. I got an error msg. TypeError: must be str, not list.
>> So I guess that may be why i had went with pickling. I needed something that 
>> would work with a list. Unless there is some other way?
>> Thanks again for taking the time to help out.
>>
>> Ken
>>
>>
> Ken, pickling is used when one wants to send information through a
> network or communicate with a database. Somebody else here knows more
> about pickling than I do. As for your list problem... I'm not exactly
> certain what you're trying to do. But I'm going with the idea that you
> have two files of information, one contains strings you like, and the
> other contains strings you dislike. And you want to read and write
> this information using Python.
>
 like = [ 'orange', 'blue', 'red' ] #things I like
 dislike = [ 'apples', 'bronze', 'bananas' ] #things I dislike
 fh = open ( 'likes.txt', 'w' ) #let's open a file stream to write
>
> # fh is my shorthand for "file handle"
> #writing a list to a file stream:
>
 for index in range( len( like )):
> fh.write( like[ index ] )
> fh.write ( '\n' ) #here i add a new line, maybe somebody else
> #knows a better way to avoid this?
>
 fh.close()
>
> #now let's read that information into a list
 fr = open ( 'info.txt' ) #I'm using python 3.2
 mylistoflikes = fr.readlines()
 mylistoflikes
> [ 'orange\n' , 'blue\n' , 'red\n' ]
 fr.close()
>
> --
> Alexander
> 7D9C597B
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

First, pickle is used to store data objects.  If you just want to
store text, you just write it and read it back from your file.  But
there are situations where you want to save an object.  Maybe you want
to have it available to another program.

So, you nearly got through your example.  You pickled your lists, and
stored them, but you didn't retrieve them.

Here is a link to review: http://wiki.python.org/moin/UsingPickle

Here is my version of your program.  It worked for me.  copy and paste
it in a file, and try it
---
import pickle


ArtyKlikes = (1,2,3)
ArtyKDislikes = (4,5,6)

file1 = open("ArtyKlikes.p", "ab")  # likesList
file2 = open("ArtyDislikes.p", "ab")  # dislikes

pickle.dump(ArtyKlikes, file1)
pickle.dump(ArtyKDislikes, file2)

file1.close()
file2.close()

ArtyLikes = pickle.load(open("ArtyKlikes.p", 'rb'))
ArtyDisLikes = pickle.load(open("ArtyDislikes.p", 'rb'))

print ArtyLikes
print ArtyDisLikes

-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to read and write to a file

2012-01-25 Thread Joel Goldstick
On Wed, Jan 25, 2012 at 10:50 AM, ken brockman  wrote:
> Thank you Joel and Alexander for your time and input.
> I had just wanted to be able to store a list and read and write to it. But
> it seems reading and writing is no go with lists, only strings, or no? Is
> there a simply way I can tweak the read write feature to do lists? I'm sorry
> if I seem a tad slow on the uptick, I'm just starting to get
> into programming and being up all night is not helping my comprehension
> skills none.  I've not as yet tried either of your suggestions, but from
> what I can gather pickling is not the right tool for the job at hand. I'm
> not looking to have it read by another program nor send it over a network.
>
> Also I have two lists and two files. Is it possible to store both lists in
> one file? I wouldn't imagine you could, but hey, doesn't hurt to ask.
> Thanks again.
>
> Ken
>
> 
> From: Joel Goldstick 
> To: Alexander 
> Cc: ken brockman ; tutor@python.org
> Sent: Wednesday, January 25, 2012 9:54 AM
>
> Subject: Re: [Tutor] how to read and write to a file
>
> On Wed, Jan 25, 2012 at 9:14 AM, Alexander  wrote:
>> On Wed, Jan 25, 2012 at 8:32 AM, ken brockman  wrote:
>>>
>>>
>>> 
>>> From: Alexander 
>>> To: ken brockman 
>>> Cc: "tutor@python.org" 
>>> Sent: Wednesday, January 25, 2012 7:38 AM
>>> Subject: Re: [Tutor] how to read and write to a file
>>>
>>>
>>>
>>> On Wed, Jan 25, 2012 at 7:19 AM, ken brockman 
>>> wrote:
>>>
>>> I would like to write to and read from a file from python. I wanted to
>>> use the file to save input to the program in a list. I have been looking
>>> around and there seems to be several ways to go about it. I tried pickling,
>>> but am having an issue with it. What would be the correct way to accomplish
>>> this? I have tried several ways, but to no avail. I get no error msg. but
>>> the list isn't retaining the info. Is pickling even the best way to do it.
>>>
>>> file1 = open("ArtyKlikes.p", "ab")  # likesList
>>> file2 = open("ArtyDislikes.p", "ab")  # dislikes
>>>
>>> pickle.dump(likesList, file1)
>>> pickle.dump(dislikeList, file2)
>>>
>>> file1.close()
>>> file2.close()
>>>
>>> Any help would be greatly appreciated.
>>>
>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>> Hi Ken. If you just want to read and write from a text file then you
>>> don't need to pickle.
>>> For example,
>>> (the file info.txt exists)
>>>
>>> >>>fh = open ( 'info.txt', 'w' )
>>> >>>fh.write ( 'peter piper picked a pack of pickled peppers.' )
>>> >>>fh.close()
>>> >>>fr = open ( 'info.txt', 'r')
>>> >>>fr.readline()
>>> 'peter piper picked a pack of pickled peppers.'
>>> >>>fr.close()
>>>
>>> or whatever.
>>> But do you have a need to use pickling?
>>> --
>>> Alexander
>>> 7D9C597B
>>>
>>> --
>>>
>>> Hey Alexander,
>>> I had to try it before I went to sleep.
>>> No good. I got an error msg. TypeError: must be str, not list.
>>> So I guess that may be why i had went with pickling. I needed something
>>> that would work with a list. Unless there is some other way?
>>> Thanks again for taking the time to help out.
>>>
>>> Ken
>>>
>>>
>> Ken, pickling is used when one wants to send information through a
>> network or communicate with a database. Somebody else here knows more
>> about pickling than I do. As for your list problem... I'm not exactly
>> certain what you're trying to do. But I'm going with the idea that you
>> have two files of information, one contains strings you like, and the
>> other contains strings you dislike. And you want to read and write
>> this information using Python.
>>
> like = [ 'orange', 'blue', 'red' ] #things I like
> dislike = [ 'apples', 'bronze', 'bananas' ] #things I dislike
> fh = open ( 'likes.txt', 'w' ) #let's open a file stream to write
>>
>> # fh is my shorthand for "file handle"
>> #writing a list to a file stream:
>>
> for index in range( len( like )):
>> fh.write( like[ index ] )
>> fh.write ( '\n' ) #here i add a new line, maybe somebody else
>> #knows a better way to avoid this?
>>
> fh.close()
>>
>> #now let's read that information into a list
> fr = open ( 'info.txt' ) #I'm using python 3.2
> mylistoflikes = fr.readlines()
> mylistoflikes
>> [ 'orange\n' , 'blue\n' , 'red\n' ]
> fr.close()
>>
>> --
>> Alexander
>> 7D9C597B
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>
> First, pickle is used to store data objects.  If you just want to
> store text, you just write it and read it back from your file.  But
> there are situations where you want to save an object.  Maybe you want
> to have it available

Re: [Tutor] how to read and write to a file

2012-01-25 Thread ken brockman
Okay, got ya. Mea Culpa. 
Being misanthropic by nature I've not used or engaged  in a interactive forum 
such as this one before . 
I do grasp that a list is more then just the information it contains. So, does 
that mean i go with pickling? And can I save  two lists in one pickled file, or 
no?

Thanks one and all, for the help.
Ken



 From: Joel Goldstick 
To: ken brockman  
Cc: tutor@python.org 
Sent: Wednesday, January 25, 2012 11:04 AM
Subject: Re: [Tutor] how to read and write to a file
 
On Wed, Jan 25, 2012 at 10:50 AM, ken brockman  wrote:
> Thank you Joel and Alexander for your time and input.
> I had just wanted to be able to store a list and read and write to it. But
> it seems reading and writing is no go with lists, only strings, or no? Is
> there a simply way I can tweak the read write feature to do lists? I'm sorry
> if I seem a tad slow on the uptick, I'm just starting to get
> into programming and being up all night is not helping my comprehension
> skills none.  I've not as yet tried either of your suggestions, but from
> what I can gather pickling is not the right tool for the job at hand. I'm
> not looking to have it read by another program nor send it over a network.
>
> Also I have two lists and two files. Is it possible to store both lists in
> one file? I wouldn't imagine you could, but hey, doesn't hurt to ask.
> Thanks again.
>
> Ken
>
> 
> From: Joel Goldstick 
> To: Alexander 
> Cc: ken brockman ; tutor@python.org
> Sent: Wednesday, January 25, 2012 9:54 AM
>
> Subject: Re: [Tutor] how to read and write to a file
>
> On Wed, Jan 25, 2012 at 9:14 AM, Alexander  wrote:
>> On Wed, Jan 25, 2012 at 8:32 AM, ken brockman  wrote:
>>>
>>>
>>> 
>>> From: Alexander 
>>> To: ken brockman 
>>> Cc: "tutor@python.org" 
>>> Sent: Wednesday, January 25, 2012 7:38 AM
>>> Subject: Re: [Tutor] how to read and write to a file
>>>
>>>
>>>
>>> On Wed, Jan 25, 2012 at 7:19 AM, ken brockman 
>>> wrote:
>>>
>>> I would like to write to and read from a file from python. I wanted to
>>> use the file to save input to the program in a list. I have been looking
>>> around and there seems to be several ways to go about it. I tried pickling,
>>> but am having an issue with it. What would be the correct way to accomplish
>>> this? I have tried several ways, but to no avail. I get no error msg. but
>>> the list isn't retaining the info. Is pickling even the best way to do it.
>>>
>>> file1 = open("ArtyKlikes.p", "ab")  # likesList
>>> file2 = open("ArtyDislikes.p", "ab")  # dislikes
>>>
>>> pickle.dump(likesList, file1)
>>> pickle.dump(dislikeList, file2)
>>>
>>> file1.close()
>>> file2.close()
>>>
>>> Any help would be greatly appreciated.
>>>
>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>> Hi Ken. If you just want to read and write from a text file then you
>>> don't need to pickle.
>>> For example,
>>> (the file info.txt exists)
>>>
>>> >>>fh = open ( 'info.txt', 'w' )
>>> >>>fh.write ( 'peter piper picked a pack of pickled peppers.' )
>>> >>>fh.close()
>>> >>>fr = open ( 'info.txt', 'r')
>>> >>>fr.readline()
>>> 'peter piper picked a pack of pickled peppers.'
>>> >>>fr.close()
>>>
>>> or whatever.
>>> But do you have a need to use pickling?
>>> --
>>> Alexander
>>> 7D9C597B
>>>
>>> --
>>>
>>> Hey Alexander,
>>> I had to try it before I went to sleep.
>>> No good. I got an error msg. TypeError: must be str, not list.
>>> So I guess that may be why i had went with pickling. I needed something
>>> that would work with a list. Unless there is some other way?
>>> Thanks again for taking the time to help out.
>>>
>>> Ken
>>>
>>>
>> Ken, pickling is used when one wants to send information through a
>> network or communicate with a database. Somebody else here knows more
>> about pickling than I do. As for your list problem... I'm not exactly
>> certain what you're trying to do. But I'm going with the idea that you
>> have two files of information, one contains strings you like, and the
>> other contains strings you dislike. And you want to read and write
>> this information using Python.
>>
> like = [ 'orange', 'blue', 'red' ] #things I like
> dislike = [ 'apples', 'bronze', 'bananas' ] #things I dislike
> fh = open ( 'likes.txt', 'w' ) #let's open a file stream to write
>>
>> # fh is my shorthand for "file handle"
>> #writing a list to a file stream:
>>
> for index in range( len( like )):
>> fh.write( like[ index ] )
>> fh.write ( '\n' ) #here i add a new line, maybe somebody else
>> #knows a better way to avoid this?
>>
> fh.close()
>>
>> #now let's read that information into a list
> fr = open ( 'info.txt' ) #I'm using python 3.2
> mylistoflikes = fr.readlines()
>

Re: [Tutor] how to read and write to a file

2012-01-25 Thread Joel Goldstick
On Wed, Jan 25, 2012 at 11:30 AM, ken brockman  wrote:
> Okay, got ya. Mea Culpa.
> Being misanthropic by nature I've not used or engaged  in a interactive
> forum such as this one before .
> I do grasp that a list is more then just the information it contains. So,
> does that mean i go with pickling? And can I save  two lists in one pickled
> file, or no?
>
> Thanks one and all, for the help.
> Ken
> 
> From: Joel Goldstick 
> To: ken brockman 
> Cc: tutor@python.org
> Sent: Wednesday, January 25, 2012 11:04 AM
>
> Subject: Re: [Tutor] how to read and write to a file
>
> On Wed, Jan 25, 2012 at 10:50 AM, ken brockman  wrote:
>> Thank you Joel and Alexander for your time and input.
>> I had just wanted to be able to store a list and read and write to it. But
>> it seems reading and writing is no go with lists, only strings, or no? Is
>> there a simply way I can tweak the read write feature to do lists? I'm
>> sorry
>> if I seem a tad slow on the uptick, I'm just starting to get
>> into programming and being up all night is not helping my comprehension
>> skills none.  I've not as yet tried either of your suggestions, but from
>> what I can gather pickling is not the right tool for the job at hand. I'm
>> not looking to have it read by another program nor send it over a network.
>>
>> Also I have two lists and two files. Is it possible to store both lists in
>> one file? I wouldn't imagine you could, but hey, doesn't hurt to ask.
>> Thanks again.
>>
>> Ken
>>
>> 
>> From: Joel Goldstick 
>> To: Alexander 
>> Cc: ken brockman ; tutor@python.org
>> Sent: Wednesday, January 25, 2012 9:54 AM
>>
>> Subject: Re: [Tutor] how to read and write to a file
>>
>> On Wed, Jan 25, 2012 at 9:14 AM, Alexander  wrote:
>>> On Wed, Jan 25, 2012 at 8:32 AM, ken brockman 
>>> wrote:


 
 From: Alexander 
 To: ken brockman 
 Cc: "tutor@python.org" 
 Sent: Wednesday, January 25, 2012 7:38 AM
 Subject: Re: [Tutor] how to read and write to a file



 On Wed, Jan 25, 2012 at 7:19 AM, ken brockman 
 wrote:

 I would like to write to and read from a file from python. I wanted to
 use the file to save input to the program in a list. I have been looking
 around and there seems to be several ways to go about it. I tried
 pickling,
 but am having an issue with it. What would be the correct way to
 accomplish
 this? I have tried several ways, but to no avail. I get no error msg.
 but
 the list isn't retaining the info. Is pickling even the best way to do
 it.

 file1 = open("ArtyKlikes.p", "ab")  # likesList
 file2 = open("ArtyDislikes.p", "ab")  # dislikes

 pickle.dump(likesList, file1)
 pickle.dump(dislikeList, file2)

 file1.close()
 file2.close()

 Any help would be greatly appreciated.

 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


 Hi Ken. If you just want to read and write from a text file then you
 don't need to pickle.
 For example,
 (the file info.txt exists)

 >>>fh = open ( 'info.txt', 'w' )
 >>>fh.write ( 'peter piper picked a pack of pickled peppers.' )
 >>>fh.close()
 >>>fr = open ( 'info.txt', 'r')
 >>>fr.readline()
 'peter piper picked a pack of pickled peppers.'
 >>>fr.close()

 or whatever.
 But do you have a need to use pickling?
 --
 Alexander
 7D9C597B


 --

 Hey Alexander,
 I had to try it before I went to sleep.
 No good. I got an error msg. TypeError: must be str, not list.
 So I guess that may be why i had went with pickling. I needed something
 that would work with a list. Unless there is some other way?
 Thanks again for taking the time to help out.

 Ken


>>> Ken, pickling is used when one wants to send information through a
>>> network or communicate with a database. Somebody else here knows more
>>> about pickling than I do. As for your list problem... I'm not exactly
>>> certain what you're trying to do. But I'm going with the idea that you
>>> have two files of information, one contains strings you like, and the
>>> other contains strings you dislike. And you want to read and write
>>> this information using Python.
>>>
>> like = [ 'orange', 'blue', 'red' ] #things I like
>> dislike = [ 'apples', 'bronze', 'bananas' ] #things I dislike
>> fh = open ( 'likes.txt', 'w' ) #let's open a file stream to write
>>>
>>> # fh is my shorthand for "file handle"
>>> #writing a list to a file stream:
>>>
>> for index in range( len( like )):
>>> fh.write( like[ index ] )
>>> fh.write ( '\n' ) #here i add a new lin

Re: [Tutor] how to read and write to a file

2012-01-25 Thread ken brockman
Joel, thanks your  first suggest worked great, except that it only reads my 
first item instead of the whole list. I will have to do some more research on 
the topic, but i do appreciate your giving me a leg up.
Also I don't understand why my last response was once again at the top of the 
list? I entered the reply at the window in the bottom of the email, like I had 
before.?Is that not the way? jeez.. I gotta get some 's, I'm almost afraid 
to hit the reply button , I don't want to screw up once again..
Ken



 From: Joel Goldstick 
To: ken brockman  
Cc: tutor@python.org 
Sent: Wednesday, January 25, 2012 12:00 PM
Subject: Re: [Tutor] how to read and write to a file
 
On Wed, Jan 25, 2012 at 11:30 AM, ken brockman  wrote:
> Okay, got ya. Mea Culpa.
> Being misanthropic by nature I've not used or engaged  in a interactive
> forum such as this one before .
> I do grasp that a list is more then just the information it contains. So,
> does that mean i go with pickling? And can I save  two lists in one pickled
> file, or no?
>
> Thanks one and all, for the help.
> Ken
> 
> From: Joel Goldstick 
> To: ken brockman 
> Cc: tutor@python.org
> Sent: Wednesday, January 25, 2012 11:04 AM
>
> Subject: Re: [Tutor] how to read and write to a file
>
> On Wed, Jan 25, 2012 at 10:50 AM, ken brockman  wrote:
>> Thank you Joel and Alexander for your time and input.
>> I had just wanted to be able to store a list and read and write to it. But
>> it seems reading and writing is no go with lists, only strings, or no? Is
>> there a simply way I can tweak the read write feature to do lists? I'm
>> sorry
>> if I seem a tad slow on the uptick, I'm just starting to get
>> into programming and being up all night is not helping my comprehension
>> skills none.  I've not as yet tried either of your suggestions, but from
>> what I can gather pickling is not the right tool for the job at hand. I'm
>> not looking to have it read by another program nor send it over a network.
>>
>> Also I have two lists and two files. Is it possible to store both lists in
>> one file? I wouldn't imagine you could, but hey, doesn't hurt to ask.
>> Thanks again.
>>
>> Ken
>>
>> 
>> From: Joel Goldstick 
>> To: Alexander 
>> Cc: ken brockman ; tutor@python.org
>> Sent: Wednesday, January 25, 2012 9:54 AM
>>
>> Subject: Re: [Tutor] how to read and write to a file
>>
>> On Wed, Jan 25, 2012 at 9:14 AM, Alexander  wrote:
>>> On Wed, Jan 25, 2012 at 8:32 AM, ken brockman 
>>> wrote:


 
 From: Alexander 
 To: ken brockman 
 Cc: "tutor@python.org" 
 Sent: Wednesday, January 25, 2012 7:38 AM
 Subject: Re: [Tutor] how to read and write to a file



 On Wed, Jan 25, 2012 at 7:19 AM, ken brockman 
 wrote:

 I would like to write to and read from a file from python. I wanted to
 use the file to save input to the program in a list. I have been looking
 around and there seems to be several ways to go about it. I tried
 pickling,
 but am having an issue with it. What would be the correct way to
 accomplish
 this? I have tried several ways, but to no avail. I get no error msg.
 but
 the list isn't retaining the info. Is pickling even the best way to do
 it.

 file1 = open("ArtyKlikes.p", "ab")  # likesList
 file2 = open("ArtyDislikes.p", "ab")  # dislikes

 pickle.dump(likesList, file1)
 pickle.dump(dislikeList, file2)

 file1.close()
 file2.close()

 Any help would be greatly appreciated.

 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


 Hi Ken. If you just want to read and write from a text file then you
 don't need to pickle.
 For example,
 (the file info.txt exists)

 >>>fh = open ( 'info.txt', 'w' )
 >>>fh.write ( 'peter piper picked a pack of pickled peppers.' )
 >>>fh.close()
 >>>fr = open ( 'info.txt', 'r')
 >>>fr.readline()
 'peter piper picked a pack of pickled peppers.'
 >>>fr.close()

 or whatever.
 But do you have a need to use pickling?
 --
 Alexander
 7D9C597B


 --

 Hey Alexander,
 I had to try it before I went to sleep.
 No good. I got an error msg. TypeError: must be str, not list.
 So I guess that may be why i had went with pickling. I needed something
 that would work with a list. Unless there is some other way?
 Thanks again for taking the time to help out.

 Ken


>>> Ken, pickling is used when one wants to send information through a
>>> network or communicate with a database. Somebody else here knows more
>>> about pickling 

Re: [Tutor] how to read and write to a file

2012-01-25 Thread Steven D'Aprano

Joel Goldstick wrote:


First of all, always remember to reply to all on the list.  That keeps
everyone in the loop.
Second, don't 'top post'.  Write your comments at the end of the
thread so that people can follow the conversation.  Sometimes its
useful to intersperse comments in someone's previous email.


"Sometimes"? I would say "almost always".

Please trim your replies. There is absolutely no need to repeat the ENTIRE 
comment thread, over and over and over again. Just quote what you need to 
establish context, and when directly answering a question or comment.


Otherwise, good advice: keep replies to the list unless you are making a 
personal/private comment, and email should be more like


  > Question
  Answer
  > Question
  Answer

instead of:


  Answer
  Answer
  > Question
  > Question


(And yes, I deliberately had one fewer answer than question in the second 
case. Top posting makes it MUCH easier to miss questions.)




--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to read and write to a file

2012-01-25 Thread Steven D'Aprano

Steven D'Aprano wrote:

(And yes, I deliberately had one fewer answer than question in the 
second case. Top posting makes it MUCH easier to miss questions.)


Gah! Brain fart! Please ignore the comment in parentheses.




--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to read and write to a file

2012-01-25 Thread Marc Tompkins
On Wed, Jan 25, 2012 at 3:30 PM, Steven D'Aprano wrote:

> Steven D'Aprano wrote:
>
>  (And yes, I deliberately had one fewer answer than question in the second
>> case. Top posting makes it MUCH easier to miss questions.)
>>
>
> Gah! Brain fart! Please ignore the comment in parentheses.
>

And I thought you were just checking our FNORD reading comprehension.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Error Checking/Defensive Programming

2012-01-25 Thread Michael Lewis
Hi everyone,

I am new to python and have a noob question.

Is it generally better to use try/except/else statements or if/elif/else?
Or, is there a time and place for each?

For a simple example, assume I want a user to enter a number

1) try:
   number = float(input('enter a number: ')
   except ValueError:
   print('enter a number.')
   else:
   print('you entered a number')

*OR*
*
*
2) number = float(input('enter a number: ')
if number >=0 or < 0:
print('you entered a number')
else:
 print('enter a number.')

Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error Checking/Defensive Programming

2012-01-25 Thread Devin Jeanpierre
On Wed, Jan 25, 2012 at 10:36 PM, Michael Lewis  wrote:
> Is it generally better to use try/except/else statements or if/elif/else?
> Or, is there a time and place for each?

There's a time and place for each. Most errors are indicated in the
form of an exception being raised, though.

> For a simple example, assume I want a user to enter a number
>
> 1) try:
>        number = float(input('enter a number: ')
>    except ValueError:
>        print('enter a number.')
>    else:
>        print('you entered a number')
>
> OR
>
> 2) number = float(input('enter a number: ')
>     if number >=0 or < 0:
>         print('you entered a number')
>     else:
>          print('enter a number.')
>

float(x) doesn't return anything if the value it's passed can't be
converted to a float. The first way is the only way.

-- Devin
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error Checking/Defensive Programming

2012-01-25 Thread Steve Willoughby

On 25-Jan-12 19:49, Devin Jeanpierre wrote:

On Wed, Jan 25, 2012 at 10:36 PM, Michael Lewis  wrote:

 if number>=0 or<  0:


As long as we're helping with this, I'll just add a comment about this 
conditional statement.  First, if you string together two expressions 
with "or" between them, they must each be complete statements.

number>=0 makes sense, but what does <0 mean?  You'd really write it as

if number >= 0 or number < 0:

However, that doesn't make sense because if "number" is something that 
can be compared with integers like 0, it will either be >= 0 or < 0, so 
the condition will always be true.  If "number" contains something that 
doesn't make sense to compare like that, then it just won't work (i.e., 
it'll likely throw an exception).  (usually :)



--
Steve Willoughby / st...@alchemy.com
"A ship in harbor is safe, but that is not what ships are built for."
PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error Checking/Defensive Programming

2012-01-25 Thread Modulok
It's easier to ask for forgiveness than permission. Ask yourself "Is this an
action that could fail in a specific way?" If yes, you need try/except. If no,
you probably need if/else. When dealing with data such as user input or opening
files and so forth, use try/except. When those actions fail, they fail in
highly specific ways. (No read/write access, no space, invalid user data, etc.)

while True:
try:
number = float(raw_input("Enter a number between 1-10: "))
except ValueError:
print("Error: You need to enter a number.")
else:
# If they got this far, we have a number of some kind.
# Check that it is in the valid range:
if number <= 10 and number >= 1:
# It's valid, stop the loop!
break;
else:
print("Error: Number must be in the range of 1-10.")
print("Yay, the number %.2f!" % number)


On the other hand, if I was looking for an internal condition, I would use
if/else:

win_number = 3
if number == 3:
print("You won!")
else:
print("You loose!")


The rule doesn't always hold true, but it's a general guideline.

Hope that helps.
-Modulok-

On 1/25/12, Michael Lewis  wrote:
> Hi everyone,
>
> I am new to python and have a noob question.
>
> Is it generally better to use try/except/else statements or if/elif/else?
> Or, is there a time and place for each?
>
> For a simple example, assume I want a user to enter a number
>
> 1) try:
>number = float(input('enter a number: ')
>except ValueError:
>print('enter a number.')
>else:
>print('you entered a number')
>
> *OR*
> *
> *
> 2) number = float(input('enter a number: ')
> if number >=0 or < 0:
> print('you entered a number')
> else:
>  print('enter a number.')
>
> Thanks for the help.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor