FreeOrion

Forums for the FreeOrion project
It is currently Sun May 26, 2013 8:46 am

All times are UTC




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Python Modules
PostPosted: Wed Jul 04, 2012 4:16 am 
Offline
Space Krill

Joined: Mon Jul 02, 2012 2:40 pm
Posts: 12
cPickle is in the Python 2.7 standard library.

If you tried to import "cpickle", then that failed because Python is case sensitive. The module is named "cPickle".

Would you please try again?


Top
 Profile  
 
 Post subject: Re: Python Modules
PostPosted: Wed Jul 04, 2012 4:18 am 
Offline
Programming, Design, and De Facto Lead
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 7899
Location: Vancouver, BC
lrh9 wrote:
If you tried to import "cpickle", then that failed because Python is case sensitive. The module is named "cPickle".

Would you please try again?
By the time you posted that, I already had, and it seems to work.


Top
 Profile  
 
 Post subject: Re: Python Modules
PostPosted: Wed Jul 04, 2012 7:38 am 
Offline
Programmer and Packager
User avatar

Joined: Wed Nov 16, 2011 12:56 pm
Posts: 769
Location: Sol III
lrh9 wrote:
cPickle is in the Python 2.7 standard library...
Yes and no. Pickle and cPickle are functionally the same thing, the difference between them is that Pickle is written in Python, whereas cPickle is written in C, and therefore of course faster. The problem is, the availability of cPickle is platform dependent. You don't have a cPickle implementation on every platform where a Python implementation is available. If you want to write truly platform independent python code, you can't rely on having cPickle at your hands.

That doesn't mean you can't use cPickle where it is available. You just have to write your code in a way that makes sure to use Pickle, if cPickle isn't available, instead of throwing an exception if the "import cPickle" statement fails. Usually this is done something like that:
Code:
try:
  import cPickle as Pickle
except:
  import Pickle
...and you're on the safe side 8)

That said, cPickle should be available on all platforms FO is currently developed for (Windows, OSX and Linux). Still, you should take the safe road and use cPickle as described above. It's simply the right way to do it.


Top
 Profile  
 
 Post subject: Re: Python Modules
PostPosted: Wed Jul 04, 2012 10:08 am 
Offline
Space Krill

Joined: Mon Jul 02, 2012 2:40 pm
Posts: 12
Vezzra, thank you for the information. Nice catch. I try to do my best to write platform independent code. I will import it as you have instructed me to do so. Thank you.


Top
 Profile  
 
 Post subject: Re: Python Modules
PostPosted: Wed Jul 04, 2012 10:12 am 
Offline
Programmer and Packager
User avatar

Joined: Wed Nov 16, 2011 12:56 pm
Posts: 769
Location: Sol III
You're welcome :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group