Re: Error importing __init__ declared variable from another package

2012-02-28 Thread Jason Veldicott
Accidentally hit post by mistake before msg completed. Any comments appreciated. It's a very simple scenario, but not sure what the mistake is. Thanks Jason On Tue, Feb 28, 2012 at 6:55 PM, Jason Veldicott wrote: > Hi, > > I have a simple configuration of modules as beneath, but an import er

Re: Error importing __init__ declared variable from another package

2012-02-28 Thread Peter Otten
Jason Veldicott wrote: > Hi, > > I have a simple configuration of modules as beneath, but an import error > is reported: > > /engine >(__init__ is empty here) >engine.py > /sim >__init__.py > > > The module engine.py imports a variable instantiated in sim.__init__ as > follows: >

check if directory is writable in a portable way

2012-02-28 Thread Andrea Crotti
How should I check if I can create files in a directory? I tried to simply check if the directory is writeable with this function: def is_writable(name): """Return true if the file is writable from the current user """ return os.access(name, os.W_OK) but that doesn't work at all on

Re: Python urllib2 problem: Name or service not known

2012-02-28 Thread Alex Borghgraef
On Feb 28, 1:36 am, Steven D'Aprano wrote: > On Mon, 27 Feb 2012 12:48:27 -0800, Alex Borghgraef wrote: > > Hi all, > > > Some time ago I've written some python code to read video data off an IP > > camera connected via a router to a laptop. Now I try to run this code on > > a different laptop and

Re: Python urllib2 problem: Name or service not known

2012-02-28 Thread Alex Borghgraef
On Feb 28, 10:50 am, Alex Borghgraef wrote: > I'll still have to find out a way to get this thing working with proxy > enabled if I ever want to connect it to our overall network. Ok, doing os.environ['http_proxy']='' before importing urllib2 seems to do the trick for that. -- Alex -- http:/

Re: check if directory is writable in a portable way

2012-02-28 Thread Tim Golden
On 28/02/2012 10:07, Andrea Crotti wrote: How should I check if I can create files in a directory? I tried to simply check if the directory is writeable with this function: def is_writable(name): """Return true if the file is writable from the current user """ return os.access(name, os.W_OK) b

Re: namespace question

2012-02-28 Thread Ben Finney
Steven D'Aprano writes: > On Sun, 26 Feb 2012 19:47:49 +1100, Ben Finney wrote: > > >> An integer variable is a variable holding an integer. A string variable > >> is a variable holding a string. A list variable is a variable holding a > >> list. > > > > And Python has none of those. Its referen

Re: check if directory is writable in a portable way

2012-02-28 Thread Andrea Crotti
On 02/28/2012 11:34 AM, Tim Chase wrote: On 02/28/12 04:07, Andrea Crotti wrote: How should I check if I can create files in a directory? So maybe the only solution that works is something like try: open(path.join('temp', 'w')) except OsError: return False else: os.remove(path

Re: check if directory is writable in a portable way

2012-02-28 Thread Tim Chase
On 02/28/12 04:07, Andrea Crotti wrote: How should I check if I can create files in a directory? So maybe the only solution that works is something like try: open(path.join('temp', 'w')) except OsError: return False else: os.remove(path.join('temp')) return True It depe

Re: check if directory is writable in a portable way

2012-02-28 Thread Tim Chase
On 02/28/12 06:01, Andrea Crotti wrote: How should I check if I can create files in a directory? But isn't there (or should there be) a windows-related library that abstracts this horrible things? Yes, there should be. There isn't as far as I know (though that doesn't mean much given my limi

pickling to an output file.

2012-02-28 Thread Smiley 4321
I have created a bytestream (readfile.pkl) from pickle.dump() already in different folder (say /tmp) succesfully. Now I wish to open the file, read it and finally write the output to a file to "output.txt". To read the file bytestream file (readfile.pkl) I did perform as -- --- import pickle def

Re: Question about sub-packages

2012-02-28 Thread Frank Millman
"Frank Millman" wrote in message news:jii0vo$36t$1...@dough.gmane.org... > Hi all > > This is a follow-up to my recent question about circular imports, but on a > different subject, hence the new thread. > [...] > > If this makes sense, my next thought was, where is the best place to put > thi

Re: check if directory is writable in a portable way

2012-02-28 Thread Tim Golden
On 28/02/2012 12:01, Andrea Crotti wrote: On 02/28/2012 11:34 AM, Tim Chase wrote: On 02/28/12 04:07, Andrea Crotti wrote: How should I check if I can create files in a directory? So maybe the only solution that works is something like try: open(path.join('temp', 'w')) except OsError: return F

Re: namespace question

2012-02-28 Thread Steven D'Aprano
On Tue, 28 Feb 2012 22:36:56 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> On Sun, 26 Feb 2012 19:47:49 +1100, Ben Finney wrote: >> >> >> An integer variable is a variable holding an integer. A string >> >> variable is a variable holding a string. A list variable is a >> >> variable ho

xlrd 0.7.3 released!

2012-02-28 Thread Chris Withers
Hi All, I'm pleased to announce the release of xlrd 0.7.3. This release just brings in some documentation updates that were missed for 0.7.2. cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- http://mail.pytho

suppressing argparse arguments in the help

2012-02-28 Thread Andrea Crotti
I have a script that might be used interactively but also has some arguments that should not be used by "normal" users. So I just want to suppress them from the help. I've read somewhere that the help=SUPPRESS should do what I want: parser.add_argument('-n', '--test_only',

Pickle performing class instantiation ??

2012-02-28 Thread Smiley 4321
I am looking for pickle performing class instantiation, something as prototype like - - Have a class - Instantiate the class with 3 parameters - pickle the class instance - generate a bytestream (.pkl) using pickle.dump -- http://mail.python.org/mailman/listinfo/python-list

Re: Pickle performing class instantiation ??

2012-02-28 Thread Smiley 4321
Am I doing the right thing for - - Have a class - Instantiate the class with 3 parameters - pickle the class instance - generate a bytestream (.pkl) using pickle.dump, simply guessing - as - --- #!/usr/bin/python import pickle class Pickle: def __init__(self, Parameter1, Parameter2, Parame

Re: suppressing argparse arguments in the help

2012-02-28 Thread Peter Otten
Andrea Crotti wrote: > I have a script that might be used interactively but also has some > arguments that > should not be used by "normal" users. > So I just want to suppress them from the help. > I've read somewhere that the help=SUPPRESS should do what I want: > > parser.add_argument('-n'

RE: Pickle performing class instantiation ??

2012-02-28 Thread Prasad, Ramit
>class Pickle: >    def __init__(self, Parameter1, Parameter2, Parameter3): >        self.PM1 = Parameter1 >        self.PM2 = Parameter2 >        self.PM3 = Parameter3 >with open('/tmp/readfile.pkl', 'wb') as f: >    pickle.dump((self.PM1, self.PM2, self.PM3), f)     >with open('/tmp/readfile.pk

Re: Pickle performing class instantiation ??

2012-02-28 Thread Peter Otten
Smiley 4321 wrote: > Am I doing the right thing for - > > - Have a class > - Instantiate the class with 3 parameters > - pickle the class instance > - generate a bytestream (.pkl) using pickle.dump, simply guessing - > > as - > > --- > #!/usr/bin/python > > import pickle > > class Pickle: >

Re: Pickle performing class instantiation ??

2012-02-28 Thread Andrew Berg
On 2/28/2012 9:54 AM, Smiley 4321 wrote: > NameError: name 'self' is not defined self is meaningless outside a class definition. You should refactor your dump, load and print code as methods inside the class definition, create an instance and call the methods on that instance. -- CPython 3.2.2 |

Re: suppressing argparse arguments in the help

2012-02-28 Thread Andrea Crotti
On 02/28/2012 04:02 PM, Peter Otten wrote: Andrea Crotti wrote: I have a script that might be used interactively but also has some arguments that should not be used by "normal" users. So I just want to suppress them from the help. I've read somewhere that the help=SUPPRESS should do what I want

Re: multiprocessing, what am I doing wrong?

2012-02-28 Thread Eric Frederich
If I do a time.sleep(0.001) right at the beginning of the run() method, then it completes fine. I was able to run it through a couple hundred times without problem. If I sleep for less time than that or not at all, it may or may not complete. On Mon, Feb 27, 2012 at 9:38 PM, MRAB wrote: > On 27/

Need to write python source with python

2012-02-28 Thread crstop
Hi All, I'm new to Python but have experience with a few other programming languages(Java, Perl, JavaScript). I'm using Python 2.7.2 and I'm trying to create and write to a file (.py) a python class and functions from python. I will also need to later read and edit the file. I realize I could

GUI for pickle read

2012-02-28 Thread Smiley 4321
Can I have some thoughts about - building a GUI to display the results of the pickle read? A prototype code should be fine on Linux. ~ BR -- http://mail.python.org/mailman/listinfo/python-list

Re: Need to write python source with python

2012-02-28 Thread Peter Otten
crs...@gmail.com wrote: > I'm new to Python but have experience with a few other programming > languages(Java, Perl, JavaScript). > > I'm using Python 2.7.2 and I'm trying to create and write to a file (.py) > a python class and functions from python. I will also need to later read > and edit the

Re: Need to write python source with python

2012-02-28 Thread 88888 Dihedral
在 2012年2月29日星期三UTC+8上午1时56分43秒,Peter Otten写道: > crs...@gmail.com wrote: > > > I'm new to Python but have experience with a few other programming > > languages(Java, Perl, JavaScript). > > > > I'm using Python 2.7.2 and I'm trying to create and write to a file (.py) > > a python class and function

Re: multiprocessing, what am I doing wrong?

2012-02-28 Thread MRAB
On 28/02/2012 17:16, Eric Frederich wrote: If I do a time.sleep(0.001) right at the beginning of the run() method, then it completes fine. I was able to run it through a couple hundred times without problem. If I sleep for less time than that or not at all, it may or may not complete. [snip] T

Re: suppressing argparse arguments in the help

2012-02-28 Thread Peter Otten
Andrea Crotti wrote: > On 02/28/2012 04:02 PM, Peter Otten wrote: >> Andrea Crotti wrote: >> >>> I have a script that might be used interactively but also has some >>> arguments that >>> should not be used by "normal" users. >>> So I just want to suppress them from the help. >>> I've read somewher

Re: GUI for pickle read

2012-02-28 Thread Jerry Hill
On Tue, Feb 28, 2012 at 12:51 PM, Smiley 4321 wrote: > Can I have some thoughts about - building a GUI to display the results of > the pickle read? > > A prototype code should be fine on Linux. It doesn't seem like it would be all that useful, though I may just be lacking in imagination. What wo

Re: Need to write python source with python

2012-02-28 Thread crstop
On Tuesday, February 28, 2012 9:56:43 AM UTC-8, Peter Otten wrote: > crs...@gmail.com wrote: > > > I'm new to Python but have experience with a few other programming > > languages(Java, Perl, JavaScript). > > > > I'm using Python 2.7.2 and I'm trying to create and write to a file (.py) > > a pyth

Listing children processes

2012-02-28 Thread Mihai Badoiu
I'm trying to compute the total CPU load of an external process and it's children. (so I cannot use resource.getrusage) For the load of the process I can just grab it from /proc/X/stat. How do I get the CPU load of the children processes? Is there an easy way to get a list of the children proce

Re: GUI for pickle read

2012-02-28 Thread Aaron France
On Tue, Feb 28, 2012 at 12:51 PM, Smiley 4321 wrote: Can I have some thoughts about - building a GUI to display the results of the pickle read? A prototype code should be fine on Linux. What on earth is this post asking? Do you want code? Opinions? -- http://mail.python.org/mailman/listinfo

Re: Question about circular imports

2012-02-28 Thread Ethan Furman
OKB (not okblacke) wrote: Anyway, testing this just reinforced my distaste for circular imports. Just trying to think about how it ought to work with a importing c but then c and d importing each other makes my brain hurt. Refactoring the files so that common code is in a separate librar

Re: Python math is off by .000000000000045

2012-02-28 Thread Ethan Furman
Michael Torrie wrote: He's simply showing you the hex (binary) representation of the floating-point number's binary representation. As you can clearly see in the case of 1.1, there is no finite sequence that can store that. You end up with repeating numbers. Thanks for the explanation. Thi

Re: Need to write python source with python

2012-02-28 Thread Peter Otten
crs...@gmail.com wrote: > On Tuesday, February 28, 2012 9:56:43 AM UTC-8, Peter Otten wrote: >> crs...@gmail.com wrote: >> >> > I'm new to Python but have experience with a few other programming >> > languages(Java, Perl, JavaScript). >> > >> > I'm using Python 2.7.2 and I'm trying to create and

Re: wcout issue

2012-02-28 Thread Dave Angel
On 02/27/2012 10:26 PM, Ben Held wrote: Hello, After upgrading from Python 2.6 to 3.2 in our application we noticed that after calling Py_Initialize, our output from std::wcout has extra spaces in it: wcout<< L"Just a test\n"; now prints out: J u s t a t e s t Any clue why? Ben Held

Re: Need to write python source with python

2012-02-28 Thread crstop
On Tuesday, February 28, 2012 11:25:33 AM UTC-8, Peter Otten wrote: > crs...@gmail.com wrote: > > > On Tuesday, February 28, 2012 9:56:43 AM UTC-8, Peter Otten wrote: > >> crs...@gmail.com wrote: > >> > >> > I'm new to Python but have experience with a few other programming > >> > languages(Java,

Re: Listing children processes

2012-02-28 Thread Chris Rebert
On Tue, Feb 28, 2012 at 10:33 AM, Mihai Badoiu wrote: > I'm trying to compute the total CPU load of an external process and it's > children.  (so I cannot use resource.getrusage)  For the load of the process > I can just grab it from /proc/X/stat.  How do I get the CPU load of the > children proce

Re: Listing children processes

2012-02-28 Thread Mihai Badoiu
Looked at that before. psutil doesn't do children. --mihai On Tue, Feb 28, 2012 at 4:35 PM, Chris Rebert wrote: > On Tue, Feb 28, 2012 at 10:33 AM, Mihai Badoiu wrote: > > I'm trying to compute the total CPU load of an external process and it's > > children. (so I cannot use resource.getrusa

Re: Listing children processes

2012-02-28 Thread Arnaud Delobelle
On 28 February 2012 21:39, Mihai Badoiu wrote: > On Tue, Feb 28, 2012 at 4:35 PM, Chris Rebert wrote: >> >> On Tue, Feb 28, 2012 at 10:33 AM, Mihai Badoiu wrote: >> > I'm trying to compute the total CPU load of an external process and it's >> > children.  (so I cannot use resource.getrusage)  Fo

alternative to with statement?

2012-02-28 Thread Craig Yoshioka
I see that there was previously a PEP to allow the with statement to skip the enclosing block... this was shot down, and I'm trying to think of the most elegant alternative. The best I've found is to abuse the for notation: for _ in cachingcontext(x): # create cached resources here # return

RE: alternative to with statement?

2012-02-28 Thread Prasad, Ramit
Craig Yoshioka wrote: >I see that there was previously a PEP to allow the with statement to skip the >enclosing block... this was shot down, and I'm trying to think of the most >elegant alternative. [..] >I would have really liked: >with cachingcontext(x): ># create cached resources here >#

Re: suppressing argparse arguments in the help

2012-02-28 Thread Calvin Spealman
On Tue, Feb 28, 2012 at 1:07 PM, Peter Otten <__pete...@web.de> wrote: > Andrea Crotti wrote: > >> On 02/28/2012 04:02 PM, Peter Otten wrote: >>> Andrea Crotti wrote: >>> I have a script that might be used interactively but also has some arguments that should not be used by "normal"

Re: alternative to with statement?

2012-02-28 Thread Chris Kaynor
On Tue, Feb 28, 2012 at 1:04 PM, Craig Yoshioka wrote: > > I see that there was previously a PEP to allow the with statement to skip the > enclosing block... this was shot down, and I'm trying to think of the most > elegant alternative. > The best I've found is to abuse the for notation: > > for

Re: alternative to with statement?

2012-02-28 Thread Terry Reedy
On 2/28/2012 5:12 PM, Prasad, Ramit wrote: Craig Yoshioka wrote: I see that there was previously a PEP to allow the with statement to skip the enclosing block... this was shot down, and I'm trying to think of the most elegant alternative. [..] I would have really liked: with cachingcontext(

Re: A quirk/gotcha of for i, x in enumerate(seq) when seq is empty

2012-02-28 Thread Rick Johnson
On Feb 24, 8:54 am, Steven D'Aprano wrote: > for...else is a very useful construct, but the name is misleading. It > took me a long time to stop thinking that the else clause executes when > the for loop was empty. Agreed. This is a major stumbling block for neophytes. > In Python 4000, I think

Re: GUI for pickle read

2012-02-28 Thread Rick Johnson
On Feb 28, 12:13 pm, Jerry Hill wrote: > On Tue, Feb 28, 2012 at 12:51 PM, Smiley 4321 wrote: > > Can I have some thoughts about - building a GUI to display the results of > > the pickle read? Sure. But first can you show us some code that reads a pickled file and prints the contents? Hint: Why

Re: alternative to with statement?

2012-02-28 Thread Craig Yoshioka
It is a bit non-normal. but I think this is a good use case as I want to create a very simple-to-use system for non-python experts to safely wrap their CLI programs in a caching architecture... that's why I lament the inability to not use the more streamlined 'with' syntax– abusing the for loo

Re: A quirk/gotcha of for i, x in enumerate(seq) when seq is empty

2012-02-28 Thread Chris Angelico
On Wed, Feb 29, 2012 at 9:56 AM, Rick Johnson wrote: > On Feb 24, 8:54 am, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: > >> In Python 4000, I think for loops should be spelled: >> >> for name in iterable: >>     # for block >> then: >>     # only if not exited with break >> else: >>  

Re: check if directory is writable in a portable way

2012-02-28 Thread Mark Hammond
On 28/02/2012 9:07 PM, Andrea Crotti wrote: How should I check if I can create files in a directory? By trying to create them there :) Presumably you want to know that so you can write something "real" - so just write that something real. The problem gets quite hard when you consider things

Re: Listing children processes

2012-02-28 Thread Mark Lawrence
On 28/02/2012 21:47, Arnaud Delobelle wrote: On 28 February 2012 21:39, Mihai Badoiu wrote: On Tue, Feb 28, 2012 at 4:35 PM, Chris Rebert wrote: On Tue, Feb 28, 2012 at 10:33 AM, Mihai Badoiu wrote: I'm trying to compute the total CPU load of an external process and it's children. (so I c

Re: Listing children processes

2012-02-28 Thread Dave Angel
On 02/28/2012 06:41 PM, Mark Lawrence wrote: On 28/02/2012 21:47, Arnaud Delobelle wrote: Please don't top-post! Also, psutil.Process.get_children() looks to me like it "does" children. You are incorrect. I've been told of by the BDFL for stating that people should not top post on any Pyth

Re: Listing children processes

2012-02-28 Thread Steven D'Aprano
On Tue, 28 Feb 2012 23:41:16 +, Mark Lawrence wrote: > I've been told of by the BDFL for stating that > people should not top post on any Python mailing list/news group. He's the BDFL of Python, not of mailing list etiquette. -- Steven -- http://mail.python.org/mailman/listinfo/python-lis

Re: Listing children processes

2012-02-28 Thread Ben Finney
Mark Lawrence writes: > On 28/02/2012 21:47, Arnaud Delobelle wrote: > > Please don't top-post! Also, psutil.Process.get_children() looks to > > me like it "does" children. > > You are incorrect. Incorrect? The only factual statement Arnaud made was about ‘psutil’. > I've been told of by the B

Re: A quirk/gotcha of for i, x in enumerate(seq) when seq is empty

2012-02-28 Thread Steven D'Aprano
On Wed, 29 Feb 2012 10:24:18 +1100, Chris Angelico wrote: > Every syntactic structure should > have the addition of a "foo:" suite, which will run when the programmer > expects it to and no other time. This would solve a LOT of problems. Indeed, when I design my killer language, the identifie

RE: alternative to with statement?

2012-02-28 Thread Prasad, Ramit
Craig Yoshioka wrote: >It is a bit non-normal. but I think this is a good use case as I want to >create a very simple-to-use system for non-python experts to safely wrap their >CLI programs in a caching architecture... that's why I lament the inability to >not use the more streamlined 'with' sy

Re: Listing children processes

2012-02-28 Thread Mark Lawrence
On 29/02/2012 00:16, Steven D'Aprano wrote: On Tue, 28 Feb 2012 23:41:16 +, Mark Lawrence wrote: I've been told of by the BDFL for stating that people should not top post on any Python mailing list/news group. He's the BDFL of Python, not of mailing list etiquette. Incorrect, I was to

python scripts solution for euler projects

2012-02-28 Thread scripts examples
Got a web site setup for solving euler problems in python, perl, ruby and javascript. Feel free to give me any feedback, thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: python scripts solution for euler projects

2012-02-28 Thread Rodrick Brown
On Tue, Feb 28, 2012 at 10:59 PM, scripts examples < example.scri...@gmail.com> wrote: > > Got a web site setup for solving euler problems in python, perl, > ruby and javascript. > > Feel free to give me any feedback, thanks. > > -- > http://mail.python.org/mailman/listinfo/python-list

Re: Error importing __init__ declared variable from another package

2012-02-28 Thread Jason Veldicott
> > > Hi, > > > > I have a simple configuration of modules as beneath, but an import error > > is reported: > > > > /engine > >(__init__ is empty here) > >engine.py > > /sim > >__init__.py > > > > > > The module engine.py imports a variable instantiated in sim.__init__ as > > follows: >

Is it necessary to call Tk() when writing a GUI app with Tkinter?

2012-02-28 Thread John Salerno
The book I'm reading about using Tkinter only does this when creating the top-level window: app = Application() app.mainloop() and of course the Application class has subclassed the tkinter.Frame class. However, in the Python documentation, I see this: root = Tk() app = Application(master=root

Re: Listing children processes

2012-02-28 Thread Ben Finney
Mark Lawrence writes: > On 29/02/2012 00:16, Steven D'Aprano wrote: > > On Tue, 28 Feb 2012 23:41:16 +, Mark Lawrence wrote: > >> I've been told of by the BDFL for stating that people should not > >> top post on any Python mailing list/news group. > > > > He's the BDFL of Python, not of maili

[no subject]

2012-02-28 Thread Brendon Joyce
-- http://mail.python.org/mailman/listinfo/python-list

Pickle handling dictionary

2012-02-28 Thread Smiley 4321
I was successful in testing pickle with multiple objects both READ & WRITE. I did WRITE as - --- #!/usr/bin/python import pickle class apple_Class(object): def __init__(self, **kwds): self.__dict__.update(kwds) myInst = apple_Class() myInst.FirstString = "Apple" myInst.SecondString =