[Tutor] Methods defined in my class are affecting all the objects at runtime.
Hello world! I obviously don't understand something important and basic, but I am having trouble figuring it out myself... I am running python v3.2.2 on a Win XP machine. My code: import card_model import random class Pile: An Object reperesenting a list of 'Card' Objects: could be a hand, discard pile, tableau or anything really. Has a display_type that is used to clarify what kind of display to use, and .deal(cards[] , new_pile(Pile Object)) and .shuffle() methods. DISPLAY_TYPES = [STACK, FAN, ACCORDION, CASCADE] def __init__(self, cards = [], display_type = STACK): self.cards = cards self.display_type = display_type def __str__(self): return_string = for i in self.cards: return_string = return_string + str(i) + \n return_string = return_string + str(self.display_type) return return_string def shuffle(self): random.shuffle(self.cards) def add(self, card_list): for i in card_list: self.cards.append(i) def deal(self, number_of_cards, position = 0): Deletes the number of cards out of the pile, starting from position (default is the top) and returns that list of cards, for communication with other piles' .add methods. dealt_list = [] try: for i in range(number_of_cards): dealt_list.append(self.cards[position]) del self.cards[position] return(dealt_list) except IndexError: print(Error, out of cards!) return(None) I had been testing it with single objects favorably, but when I instantiate two Pile objects, methods like .add or .shuffle affect all of the Pile objects in memory. At first I thought the objects were all initializing to the same space in memory, but it wasn't true. If you need to see all my modules or my tester code, I will happily post. Thanks for helping a rank beginner! -Brian ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Methods defined in my class are affecting all the objects at runtime.
Brian Stovall wrote: Hello world! I obviously don't understand something important and basic, but I am having trouble figuring it out myself... I am running python v3.2.2 on a Win XP machine. My code: import card_model import random class Pile: An Object reperesenting a list of 'Card' Objects: could be a hand, discard pile, tableau or anything really. Has a display_type that is used to clarify what kind of display to use, and .deal(cards[] , new_pile(Pile Object)) and .shuffle() methods. DISPLAY_TYPES = [STACK, FAN, ACCORDION, CASCADE] def __init__(self, cards = [], display_type = STACK): That is a common pitfall: the default values of functions and methods are evaluated only once. Therefore all Pile instances created without an explicit cards argument p = Pile() end up sharing the same cards list. The idiomatic way to avoid that problem is a default value of None: def __init__(self, cards=None, display_type=STACK): if cards is None: cards = [] # no list provided - make a new one self.cards = cards self.display_type = display_type Note that this problem can only occur with mutable types (types whose internal state can be modified at any time); the default for display_type is immutable (its state is set once and for all when the object is created) and thus cannot cause that kind of trouble. self.cards = cards self.display_type = display_type def __str__(self): return_string = for i in self.cards: return_string = return_string + str(i) + \n Have a look at str.join(). Example: \n.join(str(card) for card in self.cards) return_string = return_string + str(self.display_type) return return_string def shuffle(self): random.shuffle(self.cards) def add(self, card_list): for i in card_list: self.cards.append(i) Have a look at list.extend(). def deal(self, number_of_cards, position = 0): Deletes the number of cards out of the pile, starting from position (default is the top) and returns that list of cards, for communication with other piles' .add methods. dealt_list = [] try: for i in range(number_of_cards): dealt_list.append(self.cards[position]) del self.cards[position] Have a look at list.pop() or slices like cards[position:position+number_of_cards] return(dealt_list) except IndexError: print(Error, out of cards!) return(None) I had been testing it with single objects favorably, but when I instantiate two Pile objects, methods like .add or .shuffle affect all of the Pile objects in memory. At first I thought the objects were all initializing to the same space in memory, but it wasn't true. If you need to see all my modules or my tester code, I will happily post. Thanks for helping a rank beginner! -Brian ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Methods defined in my class are affecting all the objects at runtime.
Brian Stovall wrote: Hello world! I obviously don't understand something important and basic, but I am having trouble figuring it out myself... I am running python v3.2.2 on a Win XP machine. [...] I had been testing it with single objects favorably, but when I instantiate two Pile objects, methods like .add or .shuffle affect all of the Pile objects in memory. At first I thought the objects were all initializing to the same space in memory, but it wasn't true. The problem is not that all Pile objects are in the same space in memory, but that they all share the same cards. If you call: a = Pile() b = Pile() c = Pile() then all three Piles a, b, c share the same list of cards. If instead you explicitly call Pile([]) each time then I bet the problem will go away. Try it and see. The problem occurs in your __init__ method, where you use a default value of [] for cards: def __init__(self, cards = [], display_type = STACK): self.cards = cards self.display_type = display_type The thing is, in Python the default value is only calculated *once*, when the function or method is defined, and then reused each time. You can test this for yourself very easily: import time def test(t=time.asctime()): print(t) Call test(), wait a few seconds, and call it again, and precisely the same time will be printed. The default value for t is calculated once, then reused. Normally this is not a problem, but if the default value is a list or dict, it means that the method or function remembers state from one call to the next: def test(x, alist=[]): ... alist.append(x) # Modify the list in place. ... return alist ... test(2) # The first time you call the function, the default is [] [2] test(3) # But now the default is [2] [2, 3] test(5) # And now the default is [2, 3] [2, 3, 5] You can easily fix this problem by making sure each Pile instance gets its own brand new empty list of cards, instead of sharing the same one: def __init__(self, cards=None, display_type=STACK): if cards is None: cards = [] self.cards = cards self.display_type = display_type A couple of other minor points: Your add method can be simplified to this: def add(self, card_list): self.cards.extend(card_list) Also, your __str__ method builds up the string by repeated concatenation: def __str__(self): return_string = for i in self.cards: return_string = return_string + str(i) + \n return_string = return_string + str(self.display_type) return return_string This is generally poor practice. Without going into a lot of detail, this risks being slow in Python. Very, very, VERY slow. Depending on the details of your operating system, exact version of Python, the specific strings being used, you may not notice any slowdown, but the risk is still there. The recommended way to build up a string out of many smaller substrings is like this: def __str__(self): # First build a list of all of the substrings. substrings = [] for card in self.cards: # Please use a more descriptive name than i substrings.append(str(card)) substrings.append(str(self.display_type)) # Now join all of the substrings in one fast operation. return '\n'.join(substrings) Hope this helps, -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Methods defined in my class are affecting all the objects at runtime.
Thanks for all the wonderful help, everyone! On 10/29/11, Peter Otten __pete...@web.de wrote: Brian Stovall wrote: Hello world! I obviously don't understand something important and basic, but I am having trouble figuring it out myself... I am running python v3.2.2 on a Win XP machine. My code: import card_model import random class Pile: An Object reperesenting a list of 'Card' Objects: could be a hand, discard pile, tableau or anything really. Has a display_type that is used to clarify what kind of display to use, and .deal(cards[] , new_pile(Pile Object)) and .shuffle() methods. DISPLAY_TYPES = [STACK, FAN, ACCORDION, CASCADE] def __init__(self, cards = [], display_type = STACK): That is a common pitfall: the default values of functions and methods are evaluated only once. Therefore all Pile instances created without an explicit cards argument p = Pile() end up sharing the same cards list. The idiomatic way to avoid that problem is a default value of None: def __init__(self, cards=None, display_type=STACK): if cards is None: cards = [] # no list provided - make a new one self.cards = cards self.display_type = display_type Note that this problem can only occur with mutable types (types whose internal state can be modified at any time); the default for display_type is immutable (its state is set once and for all when the object is created) and thus cannot cause that kind of trouble. self.cards = cards self.display_type = display_type def __str__(self): return_string = for i in self.cards: return_string = return_string + str(i) + \n Have a look at str.join(). Example: \n.join(str(card) for card in self.cards) return_string = return_string + str(self.display_type) return return_string def shuffle(self): random.shuffle(self.cards) def add(self, card_list): for i in card_list: self.cards.append(i) Have a look at list.extend(). def deal(self, number_of_cards, position = 0): Deletes the number of cards out of the pile, starting from position (default is the top) and returns that list of cards, for communication with other piles' .add methods. dealt_list = [] try: for i in range(number_of_cards): dealt_list.append(self.cards[position]) del self.cards[position] Have a look at list.pop() or slices like cards[position:position+number_of_cards] return(dealt_list) except IndexError: print(Error, out of cards!) return(None) I had been testing it with single objects favorably, but when I instantiate two Pile objects, methods like .add or .shuffle affect all of the Pile objects in memory. At first I thought the objects were all initializing to the same space in memory, but it wasn't true. If you need to see all my modules or my tester code, I will happily post. Thanks for helping a rank beginner! -Brian ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Method to create small and simple database
Hello everyone, About me: This is the first time I post to Tutor@Python.org. I am brand spanking new to Python. I can create simple application, gone through a few tutorials and watched the Google Python 2 day class on Youtube. (List of classes: http://goo.gl/Ud5rg) Just yesterday I figured out how to load up a GUI made in Glade and pass singles around and what not. Huge accomplishment for me since documentation is a bit shaky for noobs like me. :) I have some programming knowledge. I learned (self tough) VB when I was in middle school and then did a intro to C++ in college. Of course mentioning that is trivial since I haven't done any programming for about 5 years or so.. But I do know basic concepts. Just need a little push in the right direction.. -- I think I know how to design my application but I would like to put it on here for you guys to review and provide me with feedback/suggestions as to the best way to go about it. -- The application: I want to build a simple application that keeps track of items borrowers check out. So the end user types in the names of /borrowers/ and also types in a list of /items/. Then the end user checks out the /items/ to the /borrowers/. The category that my application would fall under is close to /collection management tools/. Here's a list of a few other applications that do something like what I am aiming for: http://www.makeuseof.com/tag/4-open-source-collection-manager-apps/ In addition to the application keeping track of who has what, I would like to code the date the items are out, which borrowers have not borrowed anything in the last month, and so on. That said, I need to setup some kind of database like file. I don't want to have a database server though. The reason I want to build a new tool is because: A) I want to play around with Python B) My friend needs the application to be simple and geared to his needs without too many extra bells whistles -- My method: I was thinking of using the lxmal module to construct a XML file to read/write all the information. I figured this was the easiest way to do what I need since the information is setup as a tree. (Easy to think about and see) Example: app borrowers userJohn Doe/user checked out Item1:Item2:||2011/4/2/checked out userMary Doe/user checked out Item3||2011/7/22/checked out /borrowers objects itemItem1/item createdOn2011/2/1/createdOn checked_out_times32/checked_out_times itemItem2/item createdOn2011/2/1/createdOn checked_out_times22/checked_out_times itemItem3/item createdOn2011/2/1/createdOn checked_out_times1/checked_out_times /objects /app The application will not be used in an enterprise kind of environment. The application is meant to hold about 80 borrowers and about 100 items and that's about it. Is this a good way to go about my project? Is there a better easier way? I don't want to trade off better with easy. Someone once suggested on Freenode #Python that I should use a sql database. I don't remember the name of it. It was something like lightsql or something like that. That particular database didn't use a server end. I guess it spit out a txt database or something... This might be a good time to mention I know very little about database construction or sql commands. Anyhow, I am looking forward to hearing opinion's and suggestions. Thanks! -- -Joel M ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Method to create small and simple database
Joel Montes de Oca wrote: Hello everyone, About me: This is the first time I post to Tutor@Python.org. I am brand spanking new to Python. I can create simple application, gone through a few tutorials and watched the Google Python 2 day class on Youtube. (List of classes: http://goo.gl/Ud5rg) Just yesterday I figured out how to load up a GUI made in Glade and pass singles around and what not. Huge accomplishment for me since documentation is a bit shaky for noobs like me. :) I have some programming knowledge. I learned (self tough) VB when I was in middle school and then did a intro to C++ in college. Of course mentioning that is trivial since I haven't done any programming for about 5 years or so.. But I do know basic concepts. Just need a little push in the right direction.. -- I think I know how to design my application but I would like to put it on here for you guys to review and provide me with feedback/suggestions as to the best way to go about it. -- The application: I want to build a simple application that keeps track of items borrowers check out. So the end user types in the names of /borrowers/ and also types in a list of /items/. Then the end user checks out the /items/ to the /borrowers/. The category that my application would fall under is close to /collection management tools/. Here's a list of a few other applications that do something like what I am aiming for: http://www.makeuseof.com/tag/4-open-source-collection-manager-apps/ In addition to the application keeping track of who has what, I would like to code the date the items are out, which borrowers have not borrowed anything in the last month, and so on. That said, I need to setup some kind of database like file. I don't want to have a database server though. The reason I want to build a new tool is because: A) I want to play around with Python B) My friend needs the application to be simple and geared to his needs without too many extra bells whistles -- My method: I was thinking of using the lxmal module to construct a XML file to read/write all the information. I figured this was the easiest way to do what I need since the information is setup as a tree. (Easy to think about and see) Example: app borrowers userJohn Doe/user checked out Item1:Item2:||2011/4/2/checked out userMary Doe/user checked out Item3||2011/7/22/checked out /borrowers objects itemItem1/item createdOn2011/2/1/createdOn checked_out_times32/checked_out_times itemItem2/item createdOn2011/2/1/createdOn checked_out_times22/checked_out_times itemItem3/item createdOn2011/2/1/createdOn checked_out_times1/checked_out_times /objects /app The application will not be used in an enterprise kind of environment. The application is meant to hold about 80 borrowers and about 100 items and that's about it. Is this a good way to go about my project? Is there a better easier way? I don't want to trade off better with easy. Someone once suggested on Freenode #Python that I should use a sql database. I don't remember the name of it. It was something like lightsql or something like that. That particular database didn't use a server end. I guess it spit out a txt database or something... This might be a good time to mention I know very little about database construction or sql commands. Anyhow, I am looking forward to hearing opinion's and suggestions. Well, using sqlite http://docs.python.org/library/sqlite3.html may be both better and easier than lxml, but for the tiny amount of data you are planning to handle you can also make do with a few of Python's lists and dicts, and use pickle http://docs.python.org/library/pickle.html to save the data when you're done. It won't get easier than that. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] PyQt book advise
Hi, I'm looking for a book about PyQt. Can anybody recommend a good book? My shortlist is: Rapid GUI Programming with Python and QT: The Definitive Guide to PyQt Programming (Prentice Hall Open Source Software Development by Mark Summerfield Introduction to Python Programming and Developing GUI Applications with PyQT by B. M. Harwani I have another book by Summerfield, and it's VERY good, but it's twice as expensive as the other book. Thank you in advance! Cheers!! Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Method to create small and simple database
On Sat Oct 29 14:14:24 2011, Joel Montes de Oca wrote: On Sat Oct 29 13:29:59 2011, Peter Otten wrote: Joel Montes de Oca wrote: Hello everyone, About me: This is the first time I post to Tutor@Python.org. I am brand spanking new to Python. I can create simple application, gone through a few tutorials and watched the Google Python 2 day class on Youtube. (List of classes: http://goo.gl/Ud5rg) Just yesterday I figured out how to load up a GUI made in Glade and pass singles around and what not. Huge accomplishment for me since documentation is a bit shaky for noobs like me. :) I have some programming knowledge. I learned (self tough) VB when I was in middle school and then did a intro to C++ in college. Of course mentioning that is trivial since I haven't done any programming for about 5 years or so.. But I do know basic concepts. Just need a little push in the right direction.. -- I think I know how to design my application but I would like to put it on here for you guys to review and provide me with feedback/suggestions as to the best way to go about it. -- The application: I want to build a simple application that keeps track of items borrowers check out. So the end user types in the names of /borrowers/ and also types in a list of /items/. Then the end user checks out the /items/ to the /borrowers/. The category that my application would fall under is close to /collection management tools/. Here's a list of a few other applications that do something like what I am aiming for: http://www.makeuseof.com/tag/4-open-source-collection-manager-apps/ In addition to the application keeping track of who has what, I would like to code the date the items are out, which borrowers have not borrowed anything in the last month, and so on. That said, I need to setup some kind of database like file. I don't want to have a database server though. The reason I want to build a new tool is because: A) I want to play around with Python B) My friend needs the application to be simple and geared to his needs without too many extra bells whistles -- My method: I was thinking of using the lxmal module to construct a XML file to read/write all the information. I figured this was the easiest way to do what I need since the information is setup as a tree. (Easy to think about and see) Example: app borrowers userJohn Doe/user checked out Item1:Item2:||2011/4/2/checked out userMary Doe/user checked out Item3||2011/7/22/checked out /borrowers objects itemItem1/item createdOn2011/2/1/createdOn checked_out_times32/checked_out_times itemItem2/item createdOn2011/2/1/createdOn checked_out_times22/checked_out_times itemItem3/item createdOn2011/2/1/createdOn checked_out_times1/checked_out_times /objects /app The application will not be used in an enterprise kind of environment. The application is meant to hold about 80 borrowers and about 100 items and that's about it. Is this a good way to go about my project? Is there a better easier way? I don't want to trade off better with easy. Someone once suggested on Freenode #Python that I should use a sql database. I don't remember the name of it. It was something like lightsql or something like that. That particular database didn't use a server end. I guess it spit out a txt database or something... This might be a good time to mention I know very little about database construction or sql commands. Anyhow, I am looking forward to hearing opinion's and suggestions. Well, using sqlite http://docs.python.org/library/sqlite3.html may be both better and easier than lxml, but for the tiny amount of data you are planning to handle you can also make do with a few of Python's lists and dicts, and use pickle http://docs.python.org/library/pickle.html to save the data when you're done. It won't get easier than that. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Awesome Peter, Yea, sqlite3 was what the good folks on irc.freenode.net #Python told me to use but the pickle module seems like the simpliest way to get the job done. I'll look into both of them. I'm going to have to rethink how I am going to build the program using sqlite or pickle(). Thanks again -Joel M. After looking at the Python module documentation for sqlite3 (http://docs.python.org/library/sqlite3.html#module-sqlite3), it seems to me it's the best way to make the small database that I am looking for. Now I need to look for a basic tutorial on constructing a simple database (tables, rows, keys) and how to connect all that stuff together. If anyone happens to know of a good intro tutorial or documentation to database concepts, please forward it to me. Thanks! ___ Tutor maillist -
Re: [Tutor] Method to create small and simple database
On Saturday 2011 October 29 11:28, Joel Montes de Oca wrote: After looking at the Python module documentation for sqlite3 (http://docs.python.org/library/sqlite3.html#module-sqlite3), it seems to me it's the best way to make the small database that I am looking for. First, have a look at shelve, it is in the std library. -- I have seen the future and I am not in it. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Method to create small and simple database
On 29/10/11 19:28, Joel Montes de Oca wrote: After looking at the Python module documentation for sqlite3 (http://docs.python.org/library/sqlite3.html#module-sqlite3), it seems to me it's the best way to make the small database that I am looking for. SQLlite is a great way to build small scale SQL databases. However for this app I'd probably second the advice to use shelve. Shelve acts like a dictionary in a file so you can associate a list of items with a user very very easily. Now I need to look for a basic tutorial on constructing a simple database (tables, rows, keys) and how to connect all that stuff together. If anyone happens to know of a good intro tutorial or documentation to database concepts, please forward it to me. You can try the database topic in my tutorial(see below). It's only available for Python v2 at present but the translation to Python v3 (if that's what you are using) is trivial. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Installing the uncertainties module
The uncertainties module (http://packages.python.org/uncertainties/) is now available for 64-bit Python 3.2. I've downloaded uncertainties-1.8.tar.gz. I need some utility that will handle both .gz and .tar, I presume. Looking for recommendations. Dick Moores Python 3.2.2 64-bit Win 7 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Installing the uncertainties module
Richard D. Moores wrote: The uncertainties module (http://packages.python.org/uncertainties/) is now available for 64-bit Python 3.2. I've downloaded uncertainties-1.8.tar.gz. I need some utility that will handle both .gz and .tar, I presume. Looking for recommendations. Winzip handles .tar.gz files, either separately or together. http://kb.winzip.com/kb/entry/254 So does Python: see the tarfile module. http://docs.python.org/library/tarfile.html -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Installing the uncertainties module
On Sat, Oct 29, 2011 at 18:31, Richard D. Moores rdmoo...@gmail.com wrote: The uncertainties module (http://packages.python.org/uncertainties/) is now available for 64-bit Python 3.2. I've downloaded uncertainties-1.8.tar.gz. I need some utility that will handle both .gz and .tar, I presume. Looking for recommendations. Dick Moores Python 3.2.2 64-bit Win 7 Thanks for the suggestions. Right after I posted, I remembered http://www.snapfiles.com/freeware/freeware.html, and went with Peazip, which did the job. I am curious about how I could have done this just with the tarfile module. I'll look into that. Dick Moores ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Installing the uncertainties module
On 10/30/2011 12:31 PM, Richard D. Moores wrote: The uncertainties module (c /) is now available for 64-bit Python 3.2. I've downloaded uncertainties-1.8.tar.gz. I need some utility that will handle both .gz and .tar, I presume. Looking for recommendations. 7zip has always been my multi-format compressor of choice on Windows. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Installing the uncertainties module
On Sat, Oct 29, 2011 at 21:37, Richard D. Moores rdmoo...@gmail.com wrote: On Sat, Oct 29, 2011 at 18:31, Richard D. Moores rdmoo...@gmail.com wrote: The uncertainties module (http://packages.python.org/uncertainties/) is now available for 64-bit Python 3.2. I've downloaded uncertainties-1.8.tar.gz. I need some utility that will handle both .gz and .tar, I presume. Looking for recommendations. Dick Moores Python 3.2.2 64-bit Win 7 Thanks for the suggestions. Right after I posted, I remembered http://www.snapfiles.com/freeware/freeware.html, and went with Peazip, which did the job. I am curious about how I could have done this just with the tarfile module. I'll look into that. Hm. Problem: import tarfile tar = tarfile.open(C:\Users\Richard\Desktop\uncertainties-1.8.tar.gz) File stdin, line 1 SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-4: truncated \U escape What to do? Thanks, Dick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Installing the uncertainties module
On 10/30/2011 03:55 PM, Richard D. Moores wrote: On Sat, Oct 29, 2011 at 21:37, Richard D. Mooresrdmoo...@gmail.com wrote: On Sat, Oct 29, 2011 at 18:31, Richard D. Mooresrdmoo...@gmail.com wrote: The uncertainties module (http://packages.python.org/uncertainties/) is now available for 64-bit Python 3.2. I've downloaded uncertainties-1.8.tar.gz. I need some utility that will handle both .gz and .tar, I presume. Looking for recommendations. Dick Moores Python 3.2.2 64-bit Win 7 Thanks for the suggestions. Right after I posted, I rememberedhttp://www.snapfiles.com/freeware/freeware.html, and went with Peazip, which did the job. I am curious about how I could have done this just with the tarfile module. I'll look into that. Hm. Problem: import tarfile tar = tarfile.open(C:\Users\Richard\Desktop\uncertainties-1.8.tar.gz) File stdin, line 1 SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-4: truncated \U escape use forward slash for file names even in Windows, or you had to escape the backslashes 'C:\\Users\\Richard\\Desktop\\uncertainties-1.8.tar.gz' or use raw string rC:\Users\Richard\Desktop\uncertainties-1.8.tar.gz ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Installing the uncertainties module
On Sat, Oct 29, 2011 at 22:06, Lie Ryan lie.1...@gmail.com wrote: On 10/30/2011 03:55 PM, Richard D. Moores wrote: Hm. Problem: import tarfile tar = tarfile.open(C:\Users\Richard\Desktop\uncertainties-1.8.tar.gz) File stdin, line 1 SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-4: truncated \U escape use forward slash for file names even in Windows, or you had to escape the backslashes 'C:\\Users\\Richard\\Desktop\\uncertainties-1.8.tar.gz' or use raw string rC:\Users\Richard\Desktop\uncertainties-1.8.tar.gz Should have thought of that. tar = tarfile.open(C:/Users/Richard/Desktop/uncertainties-1.8.tar.gz) tar.extractall() tar.close() Thanks! Dick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor