Re: can someone teach me this?

2012-07-23 Thread E.
On 2012-07-21, Menghsiu Lee  wrote:
> Hi, 
> I have tried 1000 times to compile this python file to be an exe file
> by using py2exe and gui2exe But, it does not work out.  I am thinking
> if there can be some genius teaching me how to make this happen.  The
> link in below  is the complete code with all sources. Everything is
> open to everyone since I change this from another expert.
>
> http://dl.dropbox.com/u/63928380/blackjack.rar
>
> Thanks for your help and instructions.
>
> Best regards,
>
> menghsiu

Maybe you want to show us what you've tried so far.

-- e.
-- 
http://mail.python.org/mailman/listinfo/python-list


Lambda

2005-02-08 Thread e
here's what is probably an unusual question: 


-- 
http://mail.python.org/mailman/listinfo/python-list


Lambda

2005-02-08 Thread e
Question: WHAT IS LAMBDA? I can't figure out what it does from any 
documentation i've found anywhere. i doubt i need it but i still want to 
know what the heck it is/does/fixes/whatever! 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setting Referer for urllib.urlretrieve

2009-09-04 Thread E
On Aug 10, 10:21 am, samwyse  wrote:
> On Aug 9, 9:41 am, Steven D'Aprano 
> cybersource.com.au> wrote:
> > On Sun, 09 Aug 2009 06:13:38 -0700,samwysewrote:
> > > Here's what I have so far:
>
> > > import urllib
>
> > > class AppURLopener(urllib.FancyURLopener):
> > >     version = "App/1.7"
> > >     referrer = None
> > >     def __init__(self, *args):
> > >         urllib.FancyURLopener.__init__(self, *args)
> > >         if self.referrer:
> > >             addheader('Referer', self.referrer)
>
> > > urllib._urlopener = AppURLopener()
>
> > > Unfortunately, the 'Referer' header potentially varies for each url that
> > > I retrieve, and the way the module is written, I can't change the calls
> > > to __init__ or open. The best idea I've had is to assign a new value to
> > > my class variable just before calling urllib.urlretrieve(), but that
> > > just seems ugly.  Any ideas?  Thanks.
>
> > [Aside: an int variable is an int. A str variable is a str. A list
> > variable is a list. A class variable is a class. You probably mean a
> > class attribute, not a variable. If other languages want to call it a
> > variable, or a sausage, that's their problem.]
>
> > If you're prepared for a bit of extra work, you could take over all the
> > URL handling instead of relying on automatic openers. This will give you
> > much finer control, but it will also require more effort on your part.
> > The basic idea is, instead of installing openers, and then ask the urllib
> > module to handle the connection, you handle the connection yourself:
>
> > make a Request object using urllib2.Request
> > make an Opener object using urllib2.build_opener
> > call opener.open(request) to connect to the server
> > deal with the connection (retry, fail or read)
>
> > Essentially, you use the Request object instead of a URL, and you would
> > add the appropriate referer header to the Request object.
>
> > Another approach, perhaps a more minimal change than the above, would be
> > something like this:
>
> > # untested
> > class AppURLopener(urllib.FancyURLopener):
> >     version = "App/1.7"
> >     def __init__(self, *args):
> >         urllib.FancyURLopener.__init__(self, *args)
> >     def add_referrer(self, url=None):
> >         if url:
> >             addheader('Referer', url)
>
> > urllib._urlopener = AppURLopener()
> > urllib._urlopener.add_referrer("http://example.com/";)
>
> Thanks for the ideas.  I'd briefly considered something similar to
> your first idea, implementing my own version of urlretrieve to accept
> a Request object, but it does seem like a good bit of work.  Maybe
> over Labor Day.  :)
>
> The second idea is pretty much what I'm going to go with for now.  The
> program that I'm writing is almost a clone of wget, but it fixes some
> personal dislikes with the way recursive retrievals are done.  (Or
> maybe I just don't understand wget's full array of options well
> enough.)  This means that my referrer changes as I bounce up and down
> the hierarchy, which makes this less convenient.  Still, it does seem
> more convenient that re-writing the module from scratch.


Just wanted to add a note. I used the sample code posted above, and I
would get this syntax error:
NameError: global name 'addheader' is not defined
The fix for the code is to change the line that references addheader
to say this:
self.addheader('Referer', url)

~E
-- 
http://mail.python.org/mailman/listinfo/python-list


Single leading dash in member variable names?

2012-09-11 Thread e . doxtator
All

Python noob here.  Trying to understand a particular syntax:

class stuff:
def __init__(self):
 self._bongo = "BongoWorld"

---

What is the significance of the leading underscore in "self._bongo"?  I've seen 
this a few times and, after looking through PEP 8, I didn't see anything 
relevant, but I could have missed it.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Single leading dash in member variable names?

2012-09-11 Thread e . doxtator
On Tuesday, September 11, 2012 2:06:45 PM UTC-5, Ian wrote:
> On Tue, Sep 11, 2012 at 12:45 PM,  I wrote:
> 
> > All
> 
> >
> 
> > Python noob here.  Trying to understand a particular syntax:
> 
> >
> 
> > class stuff:
> 
> > def __init__(self):
> 
> >  self._bongo = "BongoWorld"
> 
> >
> 
> > ---
> 
> >
> 
> > What is the significance of the leading underscore in "self._bongo"?  I've 
> > seen this a few times and, after looking through PEP 8, I didn't see 
> > anything relevant, but I could have missed it.
> 
> 
> 
> Single leading underscore is a convention indicating that the name
> 
> should be considered private and not used externally.  It's a softer
> 
> version of the double leading underscore that means basically the same
> 
> thing but has syntactic significance.

Thank you!

PEP 8 says this is bad form.  What do you think?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Single leading dash in member variable names?

2012-09-12 Thread e . doxtator
On Tuesday, September 11, 2012 5:02:31 PM UTC-5, Erik Max Francis wrote:
> On 09/11/2012 01:53 PM, me wrote:
> 
> > On Tuesday, September 11, 2012 2:06:45 PM UTC-5, Ian wrote:
> 
> >> On Tue, Sep 11, 2012 at 12:45 PM,  I wrote:
> 
> >>> What is the significance of the leading underscore in "self._bongo"?  
> >>> I've seen this a few times and, after looking through PEP 8, I didn't see 
> >>> anything relevant, but I could have missed it.
> 
> >>
> 
> >> Single leading underscore is a convention indicating that the name
> 
> >> should be considered private and not used externally.  It's a softer
> 
> >> version of the double leading underscore that means basically the same
> 
> >> thing but has syntactic significance.
> 
> >
> 
> > Thank you!
> 
> >
> 
> > PEP 8 says this is bad form.  What do you think?
> 
> 
> 
> Where does it say that?

Apologies.  It's in David Goodger's "Code Like A Pythonista" in the "Naming" 
section. 
(http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#naming)
-- 
http://mail.python.org/mailman/listinfo/python-list


[Click the star to watch this topic] HOT LINKS FOR YOUTH ONLY

2012-04-11 Thread e kartheeka
[Click the star to watch this topic]HOT LINKS FOR YOUTH ONLY
-- 
http://mail.python.org/mailman/listinfo/python-list


From the crest of Olivet...

2012-04-16 Thread E Bmums

"From the crest of Olivet, Jesus looked upon Jerusalem. Fair and 
peaceful was the scene spread out before Him. It was the season of the 
Passover, and from all lands the children of Jacob had gathered there to 
celebrate the great national festival. In the midst of gardens and 
vineyards, and green slopes studded with pilgrims’ tents, rose the 
terraced hills, the stately palaces, and massive bulwarks of Israel’s 
capital. The daughter of Zion seemed in her pride to say, "I sit a 
queen, and shall see no sorrow;" as lovely then, and deeming herself as 
secure in Heaven’s favor, as when, ages before, the royal minstrel sang, 
"Beautiful for situation, the joy of the whole earth, is Mount Zion," 
"the city of the great King." Psalm 48:2. In full view were the 
magnificent buildings of the temple. The rays of the setting sun lighted 
up the snowy whiteness of its marble walls, and gleamed from golden gate 
and tower and pinnacle. "The perfection of beauty" it stood, the pride 
of the Jewish nation. What child of Israel could gaze upon the scene 
without a thrill of joy and admiration! But far other thoughts occupied 
the mind of Jesus. "When He was come near, He beheld the city, and wept 
over it." Luke 19:41. Amid the universal rejoicing of the triumphal 
entry, while palm branches waved, while glad hosannas awoke the echoes 
of the hills, and thousands of voices declared Him king, the world’s 
Redeemer was overwhelmed with a sudden and mysterious sorrow. He, the 
Son of God, the Promised One of Israel, whose power had conquered death, 
and called its captives from the grave, was in tears, not of ordinary 
grief, but of intense, irrepressible agony."   

...The Great Controversy Between Christ and Satan


Download the complete book (and Bibles) for free.

The Great Controversy Between Christ and Satan:
http://i.minus.com/1333587044/8HjTVovD97LrYZ3KDyc2xg/dsskfA6mU3djV.pdf

Updated King James Version Bible:
http://i.minus.com/1333587073/Ne92_U0VhiUXq3kBzWx9NQ/dbaNDKEKV6PBSv.pdf

NIV Bible:
http://i.minus.com/1333587032/-QTVcB_7Np4j5FYBNRlgjg/dhVcNei3tSOdP.pdf
-- 
http://mail.python.org/mailman/listinfo/python-list


From the crest of Olivet...

2012-04-28 Thread E Bmums

"From the crest of Olivet, Jesus looked upon Jerusalem. Fair and 
peaceful was the scene spread out before Him. It was the season of the 
Passover, and from all lands the children of Jacob had gathered there to 
celebrate the great national festival. In the midst of gardens and 
vineyards, and green slopes studded with pilgrims’ tents, rose the 
terraced hills, the stately palaces, and massive bulwarks of Israel’s 
capital. The daughter of Zion seemed in her pride to say, "I sit a 
queen, and shall see no sorrow;" as lovely then, and deeming herself as 
secure in Heaven’s favor, as when, ages before, the royal minstrel sang, 
"Beautiful for situation, the joy of the whole earth, is Mount Zion," 
"the city of the great King." Psalm 48:2. In full view were the 
magnificent buildings of the temple. The rays of the setting sun lighted 
up the snowy whiteness of its marble walls, and gleamed from golden gate 
and tower and pinnacle. "The perfection of beauty" it stood, the pride 
of the Jewish nation. What child of Israel could gaze upon the scene 
without a thrill of joy and admiration! But far other thoughts occupied 
the mind of Jesus. "When He was come near, He beheld the city, and wept 
over it." Luke 19:41. Amid the universal rejoicing of the triumphal 
entry, while palm branches waved, while glad hosannas awoke the echoes 
of the hills, and thousands of voices declared Him king, the world’s 
Redeemer was overwhelmed with a sudden and mysterious sorrow. He, the 
Son of God, the Promised One of Israel, whose power had conquered death, 
and called its captives from the grave, was in tears, not of ordinary 
grief, but of intense, irrepressible agony."   

...The Great Controversy Between Christ and Satan


Download the complete book (and Bibles) for free, from the mirrors 
below.


The Great Controversy Between Christ and Satan:

http://i.minus.com/1335372595/0E6HVZrNm7ay0jgHn6IUOA/dbzr787oXlIHFr.pdf
https://rapidshare.com/files/1649741361/The_Great_Controversy.pdf
https://hotfile.com/dl/153737170/594e2f9/The_Great_Controversy.pdf.html
http://www.MegaShare.com/4139813
http://netload.in/dateiynzi7FBtgz/The%20Great%20Controversy.pdf.htm
http://ul.to/25lsg6io
http://www.filefactory.com/file/2uk8o7ertopb/n/The_Great_Controversy_pdf
http://depositfiles.com/files/c7wvwxmlc
http://ifile.it/y6b49zr/The_Great_Controversy.pdf
http://filemonster.net/file/23514/the-great-controversy.pdf.html
http://www.crocko.com/F0F90DF9D43A44529E60EEB4A576E0F6/The_Great_Controv
ersy.pdf
http://www.mediafire.com/?gv4zmzrfrod9z7t
http://www.2shared.com/document/KS-GuN80/The_Great_Controversy.html
http://filevelocity.com/ugq737saizw5/The_Great_Controversy.pdf.html
http://freakshare.com/files/py3p1qtk/The_Great_Controversy.pdf.html
http://www.sendspace.com/file/105rd3
http://www.queenshare.com/66tz8u53sy91
http://www17.zippyshare.com/v/37604967/file.html
http://bayfiles.com/file/8kKT/YDv484/The_Great_Controversy.pdf


Updated King James Version Bible:

http://i.minus.com/1335372623/_-C-jUJbdr3M4lV0JUVdCg/dxqA2tjjwSdKQ.pdf
https://rapidshare.com/files/335715109/Updated_KJV_Bible.pdf
https://hotfile.com/dl/153737253/7ced0dc/Updated_KJV_Bible.pdf.html
http://www.MegaShare.com/4139832
http://netload.in/dateiyR6qK2G4WZ/Updated_KJV_Bible.pdf.htm
http://ul.to/adxm95v1
http://www.filefactory.com/file/tgzxk55g69h/n/Updated_KJV_Bible_pdf
http://depositfiles.com/files/u2rfflkp3
http://ifile.it/ya8dq26/Updated_KJV.pdf
http://filemonster.net/file/23515/updated-kjv.pdf.html
http://www.crocko.com/75C6C5C50B9F4F38A39CFC1207262933/Updated_KJV.pdf
http://www.mediafire.com/?354xtxmotc2s6iv
http://www.2shared.com/document/iw8XU2qR/Updated_KJV.html
http://filevelocity.com/celvp2pcrx5i/Updated_KJV.pdf.html
http://freakshare.com/files/v2g7k9d6/Updated_KJV.pdf.html
http://www.sendspace.com/file/lay7a6
http://www.queenshare.com/7vvv85z8trct
http://www11.zippyshare.com/v/65110611/file.html
http://bayfiles.com/file/8kMx/yuLJqD/Updated_KJV.pdf


NIV Bible:

http://i.minus.com/1335372583/-PZp68TwyHujBc5DFsmLiA/d7ElQRFQHz7ql.pdf
https://rapidshare.com/files/2600857109/NIV_Bible.pdf
https://hotfile.com/dl/153737311/3d73850/NIV_Bible.pdf.html
http://www.MegaShare.com/4139835
http://netload.in/dateiQ2Ew7dYzfx/NIV_Bible.pdf.htm
http://ul.to/58ik4f71
http://www.filefactory.com/file/48o1dxc83bj/n/NIV_Bible_pdf
http://depositfiles.com/files/bf8sz3dfn
http://ifile.it/tup0kg4/NIV.pdf
http://filemonster.net/file/23513/niv.pdf.html
http://www.crocko.com/CC2F7D7D6F124DA8BDA05601F67EFBEE/NIV.pdf
http://www.mediafire.com/?6uh6f2fzexq34lz
http://www.2shared.com/document/XXd3Licj/NIV.html
http://filevelocity.com/3i8kfkjpjiyv/NIV.pdf.html
http://freakshare.com/files/t8wldv5g/NIV.pdf.html
http://www.sendspace.com/file/qdgfvp
http://www.queenshare.com/v0ktceewuhkl
http://www1.zippyshare.com/v/65742413/file.html
http://bayfiles.com/file/8kNN/2zlsl8/NIV.pdf
-- 
http://mail.python.org/mailman/listinfo/python-list


I have no clue figuring out how to check dates in workholidays

2020-11-06 Thread J.J. E.
Hi,

Thank you for allowing me in this support mailing list. My experience with
Python is short due to my new job. My boss told me that I need to create a
code that checks yesterday's date. The conditions for returning none are
that:

   - Yesterday happens to be a holiday,
   - Yesterday turns out to be a Saturday or a Sunday.

For both reasons, it needs to return None. Now I have learned to scan a
text file, and I have learned (ROUGHLY) the structure of what seems to scan
for specific words in "Indented Comments".

The file "gwd.py" that I have joined stands for getWorkingDate. It is the
rough draft that I am creating. So what I wish is you to help me get a
basic structure of what I need to edit and get gwd.py to scan cameroon.py;
once everyday the gwd.py checks yesterday's date and if it fills the above
conditions, it returns none. That is all.

Please note that creating a separate file with the list of national
holidays is ok but then I prefer using the holidays library because it
evolves with the years, if you know what I mean. Please forgive my lack of
proper expression as well as I have been going through Python for exactly
five weeks only.

Jean Jacques ECKEBIL
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: newbie write to file question

2005-12-04 Thread Rob E
> I'm not sure what I'm
> missing so I'd appreciate some advice.
You question is pretty general and I'm not going to go over this in any
great detail, but I will make a few comments. 

*  In your if section use if ... else constructs not all the strange if 
   and then not if blocks.  Also get rid of all those unneeded if's with the 
   pass in them.  They do nothing.
*  You may want to put the heart of the code in a separate function or if 
   you need persistance, use a class.  Optional and depends on how complex
   your analysis code is going to be.  Generally one function should not
   be two deep in terms of block nesting for readabilily
   and maintainability.
*  the table initialization i.e. table = {} was outside of your main file
   scan loop, that seemed strange to me since I think you were doing this
   file by file.
*  your log writing code was indented below the the if sub_three is None:
   if block which means that it's inside that block -- that's probably not
   what you want.  Remember python defines blocks by indentation.  The
   indentation is a nice feature because python blocking is in fact like
   it looks (unlike C++).  
*  if your parsing XML and maybe SGML the python library has some special 
   tools for this.  You might want to look at the lib or search the net.

Take care,
Rob

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient lookup in list of dictionaries

2005-12-04 Thread Rob E
> Hi. I like working with lists of dictionaries since order is preserved 
> in a list when I want order and the dictionaries make it explicit what 
> I have got inside them. I find this combination very useful for storing 
> constants especially. Generally I find myself either needing to 
> retrieve the values of constants in an iterative way (as in my 
> contrived example below). Perhaps even more frequent is given one value 
> is to look up the matching value in a dict (contained in the list) and 
> then obtain the value of another element in the same dictionary.

Instead of doing this in an iterative way -- create a dictionary that
points to the correct dictionary, i.e., who's key is the search key and
whose value is the dictionary (or list of dicts if more than one).  This
approach is basically accelerating the lookup by creating a special index.

Another way of doing this is to create a class that works like an
"ordered" dictionary.  Once can do this with a little programming -- for
example by putting your data in a list and creating a dict that indexes 
the records of the list -- i.e. the key is the index and the value is the
index of the list.  This is pretty much how databases work.

Rob


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython vs. pyQt

2005-03-20 Thread Andrew E
Hans-Peter Jansen wrote:
..
While in PyQt world, I found these advantages:
 + conceptually vastly superior
 + powerful api/widgets/features
 + fast as hell due to the efficient binding of a quite efficient lib
 + cool tools, that are unicode/translation aware
 + very efficient programming environment/unbeatable productivity
While this sounds like the average sales talk, I will try to backup these
claims a bit:
> ..
I've been a wx user since around 1999 and overall I like it. It annoys 
me a *lot* sometimes, but as Qt was always prohibitively expensive for 
commercial development, it was the only real option.

The key question from my point of view is: can I write commercial 
sell-if-I-want-to applications using Qt? If it is GPL, then I guess the 
answer is 'no'?

Andrew
--
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython vs. pyQt

2005-03-20 Thread Andrew E
John J. Lee wrote:
The key question from my point of view is: can I write commercial
sell-if-I-want-to applications using Qt? If it is GPL, then I guess
the answer is 'no'?

Yes, you can write commercial apps.  It's multi-licensed (commercial,
GPL, etc.): you get to pick the license(s) you want to use.  Read the
licenses.
PyQt's licensing follows Qt's very closely, so no real complications
there.  Note PyQt (including a Qt license for use only with PyQt) is
actually far cheaper than Qt alone (if you buy Blackadder).
ok, thanks. I've just had a quick browse of the licence notes at the 
PyQt website.

I guess I meant: "can I write commercial closed-source software *without 
paying anything for Qt" - to which I sounds like the answer is 
definitely "No" :)

Andrew
--
http://mail.python.org/mailman/listinfo/python-list


module to parse "pseudo natural" language?

2005-04-17 Thread Andrew E
Hi all

I've written a python program that adds orders into our order routing
simulation system. It works well, and has a syntax along these lines:

  ./neworder --instrument NOKIA --size 23 --price MARKET --repeats 20

etc

However, I'd like to add a mode that will handle, say:

  ./neworder buy 23 NOKIA at MKT x 20

I could enter several orders either by running multiple times, or use a
comma-separated approach, like:

  ./neworder buy 23 NOKIA at MKT on helsinki, sell 20 NOKIA at market on
helsinki

The thing about this is that its a "tolerant" parser, so all of these
should also work:

  # omit words like "at", "on"
  ./neworder buy 23 NOKIA mkt helsinki

  # take any symbol for helsinki
  ./neworder buy 23 mkt helsinki

  # figure out that market=helsinki
  ./neworder buy 23 NOKIA at market price


I've started writing a simple state-based parser, usage like:

  class NaturalLanguageInsructionBuilder:

def parse( self, arglist ):
  """Given a sequence of args, return an Instruction object"""
  ...
  return Instruction( instrument, size, price, ... )


  class Instruction:
"""encapsulate a single instruction to buy, sell, etc"""

def __init__( self, instrument, size, price, ... ):
  ...


This doesn't work yet, but I know with time I'll get there.

Question is - is there a module out there that will already handle this
approach?

Thanks for any suggestions :)

Andrew
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sscanf needed

2005-04-17 Thread Andrew E
Uwe Mayer wrote:
> Hi,
> 
> I've got a ISO 8601 formatted date-time string which I need to read into a
> datetime object.
> Is there a shorter way than using regular expressions? Is there a sscanf
> function as in C?

in addition to the other comments...

I like re, because it gives me the most control. See below.


import re
import datetime

class Converter:

def __init__( self ):
self.isoPattern = re.compile( "(\d\d\d\d)-(\d\d)-(\d\d)[tT
](\d\d):(\d\d):(\d\d)" )

def iso2date( self, isoDateString ):
match = self.isoPattern.match( isoDateString )
if not match: raise ValueError( "Not in ISO format: '%s'" %
isoDateString )

return datetime.datetime(
int(match.group(1)),
int(match.group(2)),
int(match.group(3)),
int(match.group(4)),
int(match.group(5)),
int(match.group(6))
)

c = Converter()


def demo( iso ):
try:
date = c.iso2date( iso )
print "Input '%s' -> datetime: %s" % ( iso, date )
except ValueError, e:
print str(e)

demo( "2005-04-21T12:34:56" )
demo( "2005-04-21 12:34:57" )
demo( "2005-04-2 12:34:57" )


-- 
http://mail.python.org/mailman/listinfo/python-list


scipy error invalid path

2014-01-31 Thread e-letter
Readers,

Used the community edition service of activepython web site to install
python27. Within the 'bin' directory, received the following error:

$ ./easy_install-2.7 scipy
Searching for scipy
Reading https://pypi.python.org/simple/scipy/
Best match: scipy 0.13.2
Downloading 
https://pypi.python.org/packages/source/s/scipy/scipy-0.13.2.zip#md5=9befa30e546fba762a0c1695a509f731
Processing scipy-0.13.2.zip
Writing /tmp/easy_install-Ef9P39/scipy-0.13.2/setup.cfg
Running scipy-0.13.2/setup.py -q bdist_egg --dist-dir
/tmp/easy_install-Ef9P39/scipy-0.13.2/egg-dist-tmp-6SO8yB
/path/to/.local/lib/python2.7/site-packages/numpy/distutils/system_info.py:564:
UserWarning: Specified path /home/apy/atlas/lib is invalid.
  warnings.warn('Specified path %s is invalid.' % d)

There is no directory in the host computer with this home directory
name. How to solve please?
-- 
https://mail.python.org/mailman/listinfo/python-list


bw2ui installation failure

2014-02-02 Thread e-letter
Readers,

Firstly, sorry for the cross-post:
https://groups.google.com/d/topic/brightway2/-akB-OQBZi4

Any advice about forcing installation of a later version of a software please?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Gpg python installer

2015-04-01 Thread E Smitty
On Wednesday, April 1, 2015 at 4:26:40 PM UTC-7, leonardo davinci wrote:
> I am using Kleopatra(gpg for win) to verify the 3.4.3 python installer, 
> Windows x86 MSI
> 
> >. This file does 
> >not have a email in the digital signaure and I am having trouble verifying 
> >the validity of the download.
> 
> Any help would be appreciated.
> 
> >thanks
> 
> >Leo

Could you tell us what steps you have taken?
-- 
https://mail.python.org/mailman/listinfo/python-list


rhythmbox plugin problem

2015-06-24 Thread L E
Hello,

I am trying to get some old plugins I wrote to wrote on anewer version of
rhythmbox.

When I try to load the plugin I see:

(rhythmbox:3092): libpeas-WARNING **: nowplaying-lcd:
/usr/lib/rhythmbox/plugins/nowplaying-lcd/libnowplaying-lcd.so: cannot open
shared object file: No such file or directory

(rhythmbox:3092): libpeas-WARNING **: Could not load plugin module:
'nowplaying-lcd'


any ideas about what is going on here?

thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyInstaller+ Python3.5 (h5py import error)

2015-09-25 Thread Hedieh E
On Thursday, September 24, 2015 at 1:12:31 PM UTC+2, Laura Creighton wrote:
> In a message of Thu, 24 Sep 2015 02:58:35 -0700, Heli Nix writes:
> >Thanks Christian, 
> >
> >It turned out that h5py.defs was not the only hidden import that I needed to 
> >add. 
> >
> >I managed to get it working with the follwoing command adding 4 hidden 
> >imports. 
> >
> >
> >pyinstaller --hidden-import=h5py.defs --hidden-import=h5py.utils  
> >--hidden-import=h5py.h5ac --hidden-import=h5py._proxy  test.py
> >
> >
> >is there anyway that you can use to add all h5py submodules all together?
> >
> >Thanks, 
> >
> 
> Yes.  You can use a hook file.
> see: https://pythonhosted.org/PyInstaller/#using-hook-files
> 
> Laura

Thanks Laura, 
Very Useful, 

-- 
https://mail.python.org/mailman/listinfo/python-list


Getting a list in user defined selection order

2013-03-14 Thread e . tekinalp
Hello everybody,

I want to select components(vertices) in a particular Order with python.
So when I create a list the main problem is, that maya is not listing the verts 
in the correct selected order as I did. 

Here an example:

I have selected from a polySphere the following vtx

[sphere.vtx400, sphere.vtx250, sphere.vtx260, sphere.vtx500, sphere.vtx100]

so maya is giving me a list like that:

[sphere.vtx100, sphere.vtx250, sphere.vtx260, sphere.vtx400, sphere.vtx500]

I know that there is a flag in the cmds.ls that created a list in ordered 
Selection and that you have to enable the tos flag from the selectPref command

cmds.selectPref(tso = 1)
vtx = cmds.ls(os = 1, flatten = 1)
cmds.select(vtx)

But then he gives me an empty list, I also tried to toggle it in the preference 
window, but to be honest that couldn't be the way.

So how can I get a list in an userdefined selection order.

Thank you guys for any help.

Cheerio
the turkish engineer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a list in user defined selection order

2013-03-14 Thread e . tekinalp
Ah sorry this is the correct snippet

cmds.selectPref(tso = 1)
vtx = cmds.ls(os = 1, flatten = 1)
print vtx

the other one wouldn't make any sense. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting a list in user defined selection order

2013-03-14 Thread e . tekinalp
Am Donnerstag, 14. März 2013 10:34:31 UTC+1 schrieb e.tek...@gmx.de:
> Hello everybody,
> 
> 
> 
> I want to select components(vertices) in a particular Order with python.
> 
> So when I create a list the main problem is, that maya is not listing the 
> verts in the correct selected order as I did. 
> 
> 
> 
> Here an example:
> 
> 
> 
> I have selected from a polySphere the following vtx
> 
> 
> 
> [sphere.vtx400, sphere.vtx250, sphere.vtx260, sphere.vtx500, sphere.vtx100]
> 
> 
> 
> so maya is giving me a list like that:
> 
> 
> 
> [sphere.vtx100, sphere.vtx250, sphere.vtx260, sphere.vtx400, sphere.vtx500]
> 
> 
> 
> I know that there is a flag in the cmds.ls that created a list in ordered 
> Selection and that you have to enable the tos flag from the selectPref command
> 
> 
> 
> cmds.selectPref(tso = 1)
> 
> vtx = cmds.ls(os = 1, flatten = 1)
> 
> cmds.select(vtx)
> 
> 
> 
> But then he gives me an empty list, I also tried to toggle it in the 
> preference window, but to be honest that couldn't be the way.
> 
> 
> 
> So how can I get a list in an userdefined selection order.
> 
> 
> 
> Thank you guys for any help.
> 
> 
> 
> Cheerio
> 
> the turkish engineer

ah thank you Terry I was in the wrong group.. XD
-- 
http://mail.python.org/mailman/listinfo/python-list


pyRTF and Footers

2006-11-15 Thread E . Doxtator
Hi All

I've been using the pyRTF module to generate some documents that I need
for work.  In general, the module is good, and pretty simple to use.
However, I am running into a problem with footers that doesn't quite
make sense to me.

My question is this:  Is it possible to change the text of a footer
throughout an RTF document?

The data that I am using to produce my document is organized in a
simple header/detail relationship.  The document I want to produce
looks roughly like this:

---
USER001

detail data line 1
detail data line 2
detail data line 3

page footer that says "USER001, plus some other information"

**page break**

USER002

detail data line 1
detail data line 2
detail data line 3

page footer that says "USER002, plus some other information"

**page break**

USERnnn

detail data line 1
detail data line 2
detail data line 3

page footer that says "USERnnn, plus some other information"

END OF DOCUMENT

---

I've gotten everything the way I want, except for the footer.  The
footer appears on the first page, but not on any other page.

The code that generates the footer is (apologies in advance for poor
style):

---

def MakeFooter(self, facilitatir, startDate, endDate, tuID):
   section = Section()

   self.doc.Sections.append( section )

   p = Paragraph(  "%s - %s (%s - %s)" % ( facilitator, tuID,
startDate, endDate ), LINE )
   p.append( 'Page', PAGE_NUMBER, ' of ', TOTAL_PAGES )
   section.Footer.append( p )

---

The logic that calls MakeFooter is:

---

   tuDoc = MakeTUDoc()
   DR = Renderer()

   for i in range( start, end + 1 ):
  key = "Traininguser%03d" % ( i )
  tuDoc.MakeFooter( facilitator, startDate, endDate, key )
  tuDoc.MakeHeader( key, module )
  < code to populate the document with detail data >

   DR.Write( tuDoc.doc, tuDoc.OpenFile( 'JUNK' ) )

   print( 'DONE!' )

---

(Note:  the MakeHeader() method doesn't put an actual RTF header in the
document-- it just puts text in a Heading1 format into a section at the
top of the page, before the detail data.)

I had a look at the RTF 1.5 specification
(http://www.biblioscope.com/rtf15_spec.htm), and regarding headers and
footers and it's pretty thin.  I didn't see anything in the
specification regarding support for changing footer text throughout the
document.  Nothing in there that said I could do it, either.

Any ideas, anyone?

Thanks in advance.  This is an extremely helpful discussion group.

-Doc

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyRTF and Footers

2006-11-15 Thread E . Doxtator

Gabriel Genellina wrote:
> At Wednesday 15/11/2006 20:08, [EMAIL PROTECTED] wrote:
>
> >I've been using the pyRTF module to generate some documents that I need
> >for work.  In general, the module is good, and pretty simple to use.
> >However, I am running into a problem with footers that doesn't quite
> >make sense to me.
>
> First, I don't use pyRTF. The app sketch and code snippet you have
> posted look reasonable.

Thanks :)

> At least using Word, you can configure a page footer for each section
> in the document, so I think it should be posible.

I edited the document in Word without problems.  I put in several
different footers into my generated RTF document.

> If you don't get the output you want, it may be a bug in the module,
=:-O

> you are using it in the wrong way,

This is a possibility.  I took a look at the raw RTF text, and the
multiple footers are in the text.  I'm going to have to edit the
document with word and compare it to the original to see what the
difference is, I guess.

>...the feature is unsupported, etc.

Say it ain't so!

> but most likely not a bug in Python itself.
=:-O

> So a better place to ask  would be... well, it appears there is no better 
> place except asking
> the author directly :)

Anyone got his number?

> (BTW, thanks for pointing me towards pyRTF - it may be useful, so
> I'll give it a try...)

It's very useful.  I can see several applications in my job where I can
use this module.

Thanks

-Doc

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strange behavior of int()

2006-01-29 Thread Rob E
> Why is int(r/k), where r = 0.5 and k = 0.5 = 0?  Shouldn't it be 1?
> And why is the last one = 4 and not 5?

I dont' know why the differences in your exact case.  However, please
realise that Regardless of the programming language good programming 
practice is to never rely on the int of a floating point division 
-- or even the int of a floating point constant to be exactly 
the integer value you expect it to be.  This is because both 
constant representations and math operations have rounding 
error.  Instead do less precise conversions by rounding.  For 
example:

a=b/c
if (a >= 0.0):
   d = int(a+0.5)
else:
   d = int(a-0.5)

If you don't do this sort of thing your programs generally 
are  senstivie to the details of foating point rounding -- 
which is generally dependent on processor, compilier and
in pythons case probably the runtime system.

Rob
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List append

2007-09-15 Thread Rob E
On Sat, 15 Sep 2007 03:25:27 +, mouseit wrote:

> I'm trying to add an element to a list which is a property of an
> object, stored in an array. When I append to one element, all of the
> lists are appended!
> 
> Example Code:
> 
> class Test:
> array = []
> 
> myTests = [Test() , Test() , Test()]
> print len(myTests[1].array)
> myTests[0].array.append( 5 )
> print len(myTests[1].array)
> 
> prints:
> 0
> 1
> 
> This is probably a really easy question (I'm very new to python), so
> thanks in advance for your help!

Yes, that's easy:

class myclass:
   var1 = []

means that var1 is associated with the class.  If you want an attribute:

class myclass:
def __init__ (self):
self.var1 = []

is the correct way.

Rob

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List operation: Removing an item

2006-04-17 Thread Miguel E
Steven D'Aprano wrote:
> On Sat, 15 Apr 2006 22:39:37 -0600, Miguel E. wrote:
> 
> 
>>I am trying to create a function that removes an item as specified by
>>the user. Apparently, the list operation "del list[:]" deletes the
>>entire list. Below is the sample function.
> 
> 
> If you know the value of the item, and not its position:
> 
> somelist.remove("value")
> 
> This will raise an exception if "value" is not in somelist.
> 

Thank you. That fixed it.

Regards,



-M
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: scope of variables

2006-05-03 Thread Rob E
> is the code below correct?
> 
> b = 3
> def adding(a)
> print a + b
> 
> it seams not to see the up-level scope where b is defined.

Yes except for the missing : at the end of the "def" line.

Rob

-- 
http://mail.python.org/mailman/listinfo/python-list


Running files with the associated program...

2008-02-05 Thread E-Lo
Hello all,

How can I start a file (on Windows) with the associated program,

Like if I want to open a bmp file, I want to to be shown in the
program that all bmp files are associated with.

I need a python code to do this.

Thanks,
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running files with the associated program...

2008-02-06 Thread E-Lo
On Feb 6, 6:09 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Tue, 05 Feb 2008 22:34:59 -0200, E-Lo <[EMAIL PROTECTED]> escribió:
>
> > How can I start a file (on Windows) with the associated program,
>
> http://docs.python.org/lib/os-process.html#l2h-2760
>
> startfile(path[, operation])
> Start a file with its associated application.
> When operation is not specified or 'open', this acts like double-clicking
> the file in Windows Explorer, or giving the file name as an argument to
> the start command from the interactive command shell: the file is opened
> with whatever application (if any) its extension is associated.
>
> --
> Gabriel Genellina

thanks, it worked :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Python for Palm OS

2008-03-15 Thread E-Lo
Is there any other edition of Python for Palm OS instead of Pippy?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Counter Class -- Bag/Multiset

2009-01-22 Thread msrachel . e
On Jan 22, 5:41 pm, Giovanni Bajo  wrote:
> * I find it *very* confusing c.items() vs c.elements(). Items and
> elements are synonymous (again, in my understanding of English).

Would have used the term "items" but that term has a different meaning
in the context of dictionaries where "items" means (key,value) pairs.
The word "elements" is used for members of the set object and has a
parallel meaning in the context of multisets.  Since the class is a
dict subclass (as recommended by Guido), the term "items" was off
limits because it means something else.  So, "elements" as used in the
sets documentation was the next, natural choice.

Raymond
--
http://mail.python.org/mailman/listinfo/python-list


Re: Counter Class -- Bag/Multiset

2009-01-22 Thread msrachel . e
On Jan 22, 5:54 pm, Paul Rubin  wrote:
> Giovanni Bajo  writes:
> > * I'm not a native speaker, but why use the word "Counter"?
>
> I agree with this, the new functionality is welcome but I think
> the traditional term "multiset" or "bag" would have been better.

The term counter was what was originally approved.  At first, I didn't
like it but found that it had some advantages.  The main advantage is
that there are *bazillions* of programmers (including some very good
ones) who have never heard the term multiset or bag but have an
instant,
intuitive understanding of counting and counters.

Also, in the context of this implementation, "multiset" would not be a
good choice.  The mathematical entity, multiset, is defined with
elements
having a count of one or more.  In contrast, the Counter class allows
counts to go to zero or become negative.  In addition, I worried that
calling it a multiset would suggest that it has a set-like API instead
of a dict-like API.  With the former, you write c.add(elem).  With the
latter, you write c[elem] += 1.  So the name, "multiset" would be
misleading.

Bike-shed discussions aside (everyone has an opinion of how to name
things),
how do you guys like the functionality?  Do you find it useable in
real-world
use cases?

Raymond
--
http://mail.python.org/mailman/listinfo/python-list


Re: Counter Class -- Bag/Multiset

2009-01-23 Thread msrachel . e
On Jan 23, 12:27 am, bearophileh...@lycos.com wrote:
> bearophile:
>
> > Are keys restricted to be long and int values only? Or are they
> > general (referenced) objects + a control of their integral nature?
>
> Here I meant values, sorry.
> Also: what's the rationale of allowing negative values too?

The dict values can be anything, but only ints make sense in the
context of bags/multisets/counters etc.
Since it is a dict subclass, we really have no control of the
content.  It's pretty much a "consenting adults" data structure (much
like the heapq module which cannot enforce a heap condition on the
underlying list which is exposed to the user).

To block negative values, the setter methods would have to be
overridden and would dramatically slow down the major use cases for
counters (and we would not be able to let people freely convert to and
from arbitrary dicts).  Also, we would have to introduce and document
some kind of exception for attempts to set a negative value (i.e. c[x]
-= 1 could raise an exception).  This would unnecessarily complicate
the API in an attempt to limit what a user can do (perhaps barring
them from a use case they consider to be important).

So, if you don't want negative counts, I recommend that you don't
subtract more than you started off with ;-)

Raymond
--
http://mail.python.org/mailman/listinfo/python-list


Version upgrade blocked mentally

2008-11-29 Thread Adam E
I have read in my copy of Programming Python that all strings will be
Unicode and there will be a byte type.

This is mentally keeping me from upgrading to 2.6 .

I'm curious, but are there still some who prefer Python 2.5?
I don't mind constructive criticsm.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter, toplevel and images

2008-08-22 Thread Adam E
On Aug 22, 9:17 am, Pedro <[EMAIL PROTECTED]> wrote:
> Hi
>
> I'm trying to build a small application that can display some images
> in a toplevel window. I have this code:
>
> def Results(master):
> from Tkinter import Toplevel, Button, Label
> from PIL import ImageTk
>
> figures = ['first.png', 'second.png']
>
> ResultsWindow = Toplevel(master)
> ResultsWindow.title('Results')
>
> picts = [ImageTk.PhotoImage(file = x) for x in figures]
>
> butRW = Button(ResultsWindow, text = 'CLOSE', command =
> ResultsWindow.destroy)
> butRW.pack()
>
> height = sum([x.height() for x in picts])
> width = picts[0].width()
>
> y = 0
> for pict in picts:
> label = Label(ResultsWindow,image=pict).pack()
> y += pict.height()
>
> from Tkinter import Tk
> root = Tk()
> Results(root)
> root.mainloop()
>
> and I just can see a grey window with a "close" button... However,
> when I try the same code with the root I can see both images... Can
> anyone give me a tip?
>
> Thanks! :)

You can try making a class for the Tkinter.Toplevel window.  I don't
have PIL, but I know if you query for a widget's value when the window
is not yet displayed, it will give a nearly 0-by-0 size result.

You can also try to set a size for the Toplevel window and see if the
images display.

I have not encountered this before, but I only know what I have read
from books (like Programming Python by O'Reilly) and have assumed.

Good luck.
--
http://mail.python.org/mailman/listinfo/python-list


Re: rules of thumb for cross os code

2008-08-22 Thread Adam E
On Aug 22, 9:55 am, DwBear75 <[EMAIL PROTECTED]> wrote:
> I am considering using python as a replacement for a lot of bash
> scripting that I have been doing. I would like to be as cross platform
> as possible, writing scripts for both windows and linux. Are there any
> guides are general rules of thumb on
> 1) keeping code os independant
> 2) nifty lambda's or other things to create functions fit for the
> environment
> 3) capturing return codes of other executables called from python; ie
> use os.system, or popen? or ?

you can try Programming Python 3rd Edition from O'Reilly or, at least,
the code for the book, which you can get from the author's site:
http://www.rmi.net/~lutz/
Note: it contains code for Python 2.4, but I never encountered any of
the code to not work when I tried it.  There is one directory that
contains out-of-date code, which you should find easily when reading
the text files.


I'm sorry that I can only help by referring you to Python 2.4 code.
But it is useful -- PyMailGUI and PyMailCGI are great examples, just
be careful not to be fed up with the large, high-level examples.
--
http://mail.python.org/mailman/listinfo/python-list


Attachment Size and SMTP EMail

2008-09-23 Thread Eric E
Hello All -

I am using python to send an email with a large zip file as an
attachment.  I successfully sent a 52M attachment.  If I try to send a
63M attachment or larger, the message never gets through.  I do not
get any errors in my python code.  I pasted my python code below.

from email.MIMEBase import MIMEBase
from email.MIMEMultipart import MIMEMultipart
from email import Encoders
import smtplib,os

mssg = MIMEMultipart()
part = MIMEBase('application',"octet-stream")
part.set_payload(open(zipFileName,"rb").read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' %
os.path.basename(zipFileName))
mssg.attach(part)

s = smtplib.SMTP('localhost')
s.set_debuglevel(1)
s.sendmail(fromAddr,toAddr,mssg.as_string())
s.quit()

I am using a Fedora Core 6 system with python 2.4.4.

Any suggestions on what could be limiting the attachment size or how I
could troubleshoot this?

Thanks!
EricE
--
http://mail.python.org/mailman/listinfo/python-list


Re: Attachment Size and SMTP EMail

2008-09-23 Thread Eric E
On Sep 23, 9:52 am, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2008-09-23, Eric E <[EMAIL PROTECTED]> wrote:
>
> > I am using python to send an email with a large zip file as an
> > attachment.  I successfully sent a 52M attachment.  If I try
> > to send a 63M attachment or larger, the message never gets
> > through.  I do not get any errors in my python code.
>
> Does sending large attachements with other SMTP clients using
> the same SMTP server work?
>
> --
> Grant Edwards   grante Yow! Zippy's brain cells
>   at   are straining to bridge
>visi.comsynapses ...


I do not know for sure.  I recently downloaded msmtp 1.4.16 and am
still in the process of trying to get it to work.
--
http://mail.python.org/mailman/listinfo/python-list


Re: What's The Best Editor for python

2006-03-24 Thread Miguel E.
PythonStudent wrote:
> Hi,
> Can one of you say to me what's the best editor for editing the python
> programs ( for linux or windows )


What may be "best" for me, may not necessarily work for you nor anybody
else. Personally, I like to use Kate, Pico, or Joe on Linux, and
Notepad2 or IDLE editor for Windows.

Cheers,


-M
-- 
http://mail.python.org/mailman/listinfo/python-list


List operation: Removing an item

2006-04-15 Thread Miguel E.
Hi,

I've been (self) studying Python for the past two months and I have had
no background in OOP whatsoever.

I was able to write an interactive program that randomly selects an item
 from a list. From a Main Menu, the user has the option to add items to
an empty list, show the list, run the random selector, and of course
quit the program. The program also complains if a user tries to add an
item that is already in the list prompting the user to enter another item.

I am trying to create a function that removes an item as specified by
the user. Apparently, the list operation "del list[:]" deletes the
entire list. Below is the sample function.

Any ideas, suggestions, or tips on the list operation I should be using,
or a better way of writing this?

TIA





shopList = ['eggs', 'milk', 'bread', 'juice', 'fruit', 'deli']

def removeItem():
   "Remove an item from the list"
   print
   for items in shopList:
  print items
   print
   dlete = raw_input("Enter the item you want to remove: ")
   print
   for item in shopList:
  if dlete in shopList:
 del shopList[:]  # <--What is the correct function to use?
 print "%s has been removed" % dlete
 print "The new list is now", shopList
  else:
 print "Item is not in the list"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What's wrong with this code?

2012-07-23 Thread Russell E. Owen
In article 
,
 Chris Angelico  wrote:

> On Tue, Jul 24, 2012 at 12:50 AM, Stone Li  wrote:
> >
> > I'm totally confused by this code:
> >
> > Code:
> 
> Boiling it down to just the bit that matters:
> 
> c = None
> d = None
> x = [c,d]
> e,f = x
> c = 1
> d = 2
> print e,f
> 
> When you assign "e,f = x", you're taking the iterable x and unpacking
> its contents. There's no magical "referenceness" that makes e bind to
> the same thing as c; all that happens is that the objects in x gain
> additional references. When you rebind c and d later, that doesn't
> change x, nor e/f.
> 
> What you've done is just this:
> 
> x = [None, None]
> e,f = x
> c = 1
> d = 2
> print e,f
> 
> It's clear from this version that changing c and d shouldn't have any
> effect on e and f. In Python, any time you use a named variable in an
> expression, you can substitute the object that that name is
> referencing - it's exactly the same. (That's one of the things I love
> about Python. No silly rules about what you can do with a function
> return value - if you have a function that returns a list, you can
> directly subscript or slice it. Yay!)

Good explanation.

Perhaps what the original poster needs is a container of some kind, e.g. 
a class with the value as an instance variable. Then you can pass around 
references to the container and read or modify the value(s) stored in it 
when you need them.

Here is a simple example:

class Container(object):
   def __init__(self, value):
   self.value = value

c = Container(5)
d = Container(6)
x = [c, d]
e, f = x
c.value = None
d.value = "hello"
print e.value, f.value
None "hello"

-- Russell

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter bug in Entry widgets on OS X

2012-09-13 Thread Russell E. Owen
In article ,
 Kevin Walzer  wrote:

> On 8/31/12 6:18 AM, Arnaud Delobelle wrote:
> > I'm very inexperienced with Tkinter (I've never used it before).  All
> > I'm looking for is a workaround, i.e. a way to somehow suppress that
> > output.
> 
> What are you trying to do? Navigate the focus to another widget? You 
> should use the tab bar for that, not the arrow key. The entry widget is 
> a single-line widget, and doesn't have up/down as the text widget does.

Based on other replies it looks as if the OP found a way to intercept 
the event with suitable binding.

But I can answer the "why": on Mac OS X in a one-line text box up-arrow 
should move the cursor to the beginning and down-arrow to the end. 
That's standard behavior.

In any case I can't imagine ever wanting to see special chars get added 
when arrow keys are pressed. The default behavior of the Entry widget is 
unfortunate.

-- Russell

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Keeping a Tkinter GUI alive during a long running process

2012-12-26 Thread Russell E. Owen
In article ,
 Kevin Walzer  wrote:

> I maintain a Tkinter application that's a front-end to to a package 
> manger, and I have never been able to find a way to keep the app from 
> locking up at some point during the piping in of the package manager's 
> build output into a text widget. At some point the buffer is overwhelmed 
> and the app simply can't respond anymore, or writes data to the text 
> widget after locking up for a period.
> 
> I've long used the typical Tkinter design pattern of opening a pipe to 
> the external command, and letting it do its thing. However, after a 
> time, this locks up the app. If I try to throttle the buffer with some 
> combination of "update" or "after" or "update_idletasks," that keeps the 
> data flowing, but it comes in too slowly and keeps flowing in long after 
> the external process has terminated.
> 
> Below is a sample function that illustrates how I approach this issue. 
> Can someone suggest a better approach?
> 
>   #install a fink package
>  def installPackage(self):
> 
>  self.package = self.infotable.getcurselection()
>  if not self.package:
>  showwarning(title='Error', message='Error', detail='Please 
> select a package name.', parent=self)
>  return
>  else:
>  self.clearData()
>  self.packagename = self.package[0][1]
>  self.status.set('Installing %s' % self.packagename)
>  self.setIcon(self.phynchronicity_install)
>  self.playSound('connect')
>  self.showProgress()
>  self.file = Popen('echo %s | sudo -S %s -y install %s' % 
> (self.passtext, self.finkpath.get(), self.packagename), shell=True, 
> bufsize=0, stdout=PIPE).stdout
>  for line in self.file:
>  self.inserturltext(line)
>  self.after(5000, self.update_idletasks)

I suggest you use the threading or multiprocessing module: call 
subprocess.Popen in the spawned thread or process, read stdout in a 
tight loop write the result into a queue. Then have your main process 
asynchronously read the queue using polling.

It sounds a bit complicated, but in lieu of a way to asynchronously read 
the stdout pipe, I don't know what else to do that's safe.

Another option to consider is to use Twisted framework, which has its 
own support for running tasks. However, if you are not using Twisted 
already, it's a big addition.

-- Russell

-- 
http://mail.python.org/mailman/listinfo/python-list


Generator problem: parent class not seen

2012-02-01 Thread Russell E. Owen
I have an odd and very intermittent problem in Python script. 
Occasionally it fails with this error:

Traceback (most recent call last):
 File 
"/Applications/APO/TTUI.app/Contents/Resources/lib/python2.7/TUI/Base/Bas
eFocusScript.py", line 884, in run
 File 
"/Applications/APO/TTUI.app/Contents/Resources/lib/python2.7/TUI/Base/Bas
eFocusScript.py", line 1690, in initAll
TypeError: unbound method initAll() must be called with BaseFocusScript 
instance as first argument (got ScriptClass instance instead)
self=; class hierarchy=[(, (,)), [(, 
(,))]]

The code looks like this:

def run(self, sr):
try:
self.initAll()

except Exception:
traceback.print_exc(file=sys.stderr)
sys.stderr.write("self=%r; class hierarchy=%s\n" % (self, 
inspect.getclasstree([type(self)])))
raise

As a detail that may be important: the code is a generator that is being 
run by a script runner class (an instance of which is passed into the 
run function as argument sr). When the user starts a script the script 
runner calls the script's "run" generator. The script runner calls the 
run generator again later when conditions are right (e.g. data that is 
being waited for arrives, a time limit is reached...). In this case the 
failure occurs at the very start of the script, so a yield has not yet 
executed.

I am puzzled why Python thinks the class type is wrong, given the output 
of inspect.getclasstree. Any ideas on what might be wrong and how to 
track it down (and why it would be so intermittent)?

-- Russell

-- 
http://mail.python.org/mailman/listinfo/python-list


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

2012-03-05 Thread Russell E. Owen
In article 
<3d0bf288-fa5d-48e5-9529-db92d420a...@1g2000yqv.googlegroups.com>,
 Rick Johnson  wrote:

> On Feb 29, 11:24 pm, Terry Reedy  wrote:
> > On 2/29/2012 10:22 PM, Rick Johnson wrote:
> 
> > > PS: I would highly suggest against using the "from Tkinter import *".
> > > Instead, use "import Tkinter as tk" and prefix all module contents
> > > with "tk.".
> >
> > I have changed the example to do that. I also showed the alternate to
> > initialize a widget. Here is the current version, tested on Windows 3.2.2.
> >
> > import tkinter as tk
> >
> > class Application(tk.Frame):
> >      def __init__(self, master=None):
> >          tk.Frame.__init__(self, master)
> >          self.pack()
> 
> With all due respect, I would also recommend against "self packing" a
> widget. And i can speak from experience on this issue. There was a
> time when i was self-packing lots of custom compund widgets; then i
> realized later the shortcomings of such action; what if you need to
> use the grid or place geometry mangers instead? So remove the
> self.pack line and add a line to the bottom:
> 
> > root = tk.Tk()
> > app = Application(master=root)
> > app.pack() # <-- added this line
> > app.mainloop()

I agree. Application is simply another widget, like Entry or Canvas. its 
contents should be packed or gridded (as appropriate) into itself, but 
the user should then pack or grid the Application widget as appropriate.

That makes the code much more reusable.

-- Russell

-- 
http://mail.python.org/mailman/listinfo/python-list


pickle question: sequencing of operations

2012-05-04 Thread Russell E. Owen
What is the sequence of calls when unpickling a class with __setstate__?

>From experimentation I see that __setstate__ is called and __init__ is 
not, but I think I need more info.

I'm trying to pickle an instance of a class that is a subclass of 
another class that contains unpickleable objects.

What I'd like to do is basically just pickle the constructor parameters 
and then use those to reconstruct the object on unpickle, but I'm not 
sure how to go about this. Or an example if anyone has one.

-- Russell

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pickle question: sequencing of operations

2012-05-08 Thread Russell E. Owen
In article ,
 "Russell E. Owen"  wrote:

> What is the sequence of calls when unpickling a class with __setstate__?
> 
> >From experimentation I see that __setstate__ is called and __init__ is 
> not, but I think I need more info.
> 
> I'm trying to pickle an instance of a class that is a subclass of 
> another class that contains unpickleable objects.
> 
> What I'd like to do is basically just pickle the constructor parameters 
> and then use those to reconstruct the object on unpickle, but I'm not 
> sure how to go about this. Or an example if anyone has one.

The following seems to work, but I don't know why:
def __getstate__(self):
   ...return the argument dict needed for __init__

def __setstate__(self, argdict):
   self.__init__(**argdict)

-- Russell

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pickle question: sequencing of operations

2012-05-09 Thread Russell E. Owen
In article 
,
 Ian Kelly  wrote:

> On Tue, May 8, 2012 at 1:19 PM, Russell E. Owen  wrote:
> > In article ,
> >  "Russell E. Owen"  wrote:
> >
> >> What is the sequence of calls when unpickling a class with __setstate__?
> 
> I believe it just calls object.__new__ followed by
> yourclass.__setstate__.  So at the point __setstate__ is called, you
> have a pristine instance of whatever class you're unpickling.

I was wondering. I override __new__ (and __init__) to print messages and 
was quite surprised to only see __new__being called when the object was 
first created, not when it was being unpickled. But maybe there's 
something funny about my override that caused unpickle to ignore it and 
use the default version. I hope so. I can't see how the object could be 
constructed during unpickle without calling __new__. But that's one 
reason I was curious about the unpickling sequence of operations.

-- Russell

-- 
http://mail.python.org/mailman/listinfo/python-list


what does newP = func(code,p) do?

2012-05-16 Thread e-mail mgbg25171
def execute (code) :
p = 0
while p < len(code) :
func = code[p]
p += 1
newP = func(code,p)
if newP != None :
p = newP

I'm trying to work out what this does

code is a list of function addresses and numbers
What on earth is funct(code,p) doing???

My understanding so far is...
set p to 0
while p is less than the number of elements in list code keep doing what
follows...
set func to the first element in the list
increment the list index p
?
if newP is not null then set the list index p to ?
Can someone please explain in english what ? is
Thank you in anticipation

BTW the link for this stuff is

http://openbookproject.net/py4fun/forth/forth.html
to see the thing in action ie the download link is on the above page

Here's a listing of the output from this proc for the following forth input
i.e. I put some print statements in
but have no idea how
newP set to func( [, 4] , 1 ) i.e.  2
results in 2
and then
newP set to func( [] , 1 ) i.e.  None
results in None
???


Forth> 5 4 + .

1st line of execute__
code =  [, 5]
p =  0
1st line of while__
func = code[ 0 ] i.e.  
incrementing p to  1
newP set to func( [, 5] , 1 ) i.e.  2
p = newP i.e.  2

1st line of execute__
code =  [, 4]
p =  0
1st line of while__
func = code[ 0 ] i.e.  
incrementing p to  1
newP set to func( [, 4] , 1 ) i.e.  2
p = newP i.e.  2

1st line of execute__
code =  []
p =  0
1st line of while__
func = code[ 0 ] i.e.  
incrementing p to  1
newP set to func( [] , 1 ) i.e.  None

1st line of execute__
code =  []
p =  0
1st line of while__
func = code[ 0 ] i.e.  
incrementing p to  1
13
newP set to func( [] , 1 ) i.e.  5
None
Forth>
-- 
http://mail.python.org/mailman/listinfo/python-list


what does newP = func(code,p) do?

2012-05-16 Thread e-mail mgbg25171
It's been a long time since I did any Python and I've never done that
In C I'm used to storing function ptrs and then having to use some other
constructs to call them.
To be able to store func and then use func to call itself like that threw
me...it's very elegant.
Thank you very much for your very lucid explanation and for taking the time
to provide it.
Best Regards
-- 
http://mail.python.org/mailman/listinfo/python-list


what do these mean

2012-05-20 Thread e-mail mgbg25171
There's a little forth program written in python here
#http://openbookproject.net/py4fun/forth/forth.py
I'm struggling to understand what these lines mean.

def rJnz (cod,p) : return (cod[p],p+1)[ds.pop()]
def rJz  (cod,p) : return (p+1,cod[p])[ds.pop()==0]

Specifically I'm stuck on what (code[p], followed by p+1 does inside the
brackets
and also what [ds.pop()] abd [ds.pop==0] does afterwards
I do know that
p is an integer
cod[p] is one of a list of functions that are stored in cod
ds.pop() is popping the top of the ds list and
ds.pop() == 0 either means that the result popped is 0 or that there are no
items left in list ds[]

Any help much appreciated
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nonuniform PRNG?

2022-12-07 Thread Robert E. Beaudoin
One thing you could do is to apply von Neumann de-biasing to convert a
string of output bits from your biased PRNG to an unbiased string, and
test the de-biased output.  If such tests pass I don't know that you
can be satisfied thaty your biased PRNG is close to a theorieical
biased random bit stream, but if they fail that should indicate a
problem.

Robert E. Beaudoin


On Wed, 7 Dec 2022 11:05:53 -0500
David Lowry-Duda  wrote:

> Inspired by the recent thread about pseudorandom number generators on 
> python-ideas (where I also mistakenly first wrote this message), I
> began to wonder: suppose that I had a pseudorandom number generator
> that attempted to generate a nonuniform distribution. Suppose for
> instance that it was to generate a 0 bit 2/3 of the time, and a 1 bit
> 1/3 of the time.
> 
> How would one go about testing this PRNG against an idealized
> (similarly biased) PRNG?
> 
> - DLD


-- 
https://mail.python.org/mailman/listinfo/python-list


why no camelCase in PEP 8?

2020-05-18 Thread Lance E Sloan
I've been using Python for about 18 years.  Several things have changed in the 
language in those years.  I don't disagree with most of it, but one of the 
things that annoys me is the disapproval of using camelCase to name symbols 
such as variables, functions, etc.

I think PEP 8, the "Style Guide for Python Code" 
(https://www.python.org/dev/peps/pep-0008/), came out shortly after I began 
using Python.  I think the old habits of the people I worked with and the 
relative lack of tools like Flake8 and Pylint led to the standard being 
ignored.  However, now I see many developers really want to adhere to the 
standard.

My preference for using camelCase (in PEP 8, AKA mixedCase) is putting me at 
odds with my colleagues, who point to PEP 8 as "the rules".  I have reasons for 
my preferring camelCase.  I suspect the reasons the PEP 8 authors have for not 
using it are probably as strong as my reasons.  So our reasons probably nullify 
each other and what's left is simple preference.

So, I'd like to know what was the reason behind favoring snake_case (AKA 
lower_case_with_underscores) in PEP 8 instead of camelCase.

Does anyone in this group know?
-- 
https://mail.python.org/mailman/listinfo/python-list


Python script produces "sem_trywait: Permission denied"

2005-10-18 Thread Mark E. Hamilton
Hi,

I've seen this question posted many places arount the Internet, but I've 
not seen any answers. We've been seeing this same error for some time, 
probably as long as Hudson has (given that it's now mid-October 2005); 
we just ignored it, since it didn't seem to cause problems.

However, if anyone does have a solution to it I'd like to see it. I hate 
having unresolved wierdnesses in our code.

-- 

Mark E. Hamilton
Orion International Technologies, Inc.
Sandia National Laboratory, NM.
505-844-7666

-- 
http://mail.python.org/mailman/listinfo/python-list


Python script produces "sem_trywait: Permission denied"

2005-10-18 Thread Mark E. Hamilton
Sorry, I probably should have re-stated the problem:

We're using Python 2.3.5 on AIX 5.2, and get the follow error messages 
from some of our code. I haven't yet tracked down exactly where it's 
coming from:

sem_trywait: Permission denied
sem_wait: Permission denied
sem_post: Permission denied

We don't run these scripts as root, so I can't say whether they work as 
root. I suspect they would, though, since root has permissions to do 
anything.

-- 

Mark E. Hamilton
Orion International Technologies, Inc.
Sandia National Laboratory, NM.
505-844-7666

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter or Python issue?

2005-10-19 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Eric Brunel" <[EMAIL PROTECTED]> wrote:

>You should now see why it works here: your first tkFont.Font is remembered at 
>Python level in a variable. So it is not discarded once the tag_config is 
>over. So the second tkFont.Font is not allocated at the same location, so it 
>doesn't have the same id, and it doesn't have the same name at tcl level. This 
>is the general solution to the problem: keep your fonts in Python variables, 
>so they won't be discarded and their names will never be re-used.

Yes. I consider this dangerous behavior, by the way and submitted a 
patch (that was not accepted) that would prevent this garbage collection.

tkFont is Tkinter's interface to tk named fonts. If you create a tkFont 
instance for a named font and then let it disappear, the named font 
disappears, even if other tkFont instances exist that map the same named 
font.

-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


frozenset/subclassing/keyword args

2005-10-31 Thread Mark E. Fenner
Hello all,

I was migrating some code from sets.ImmutableSet to frozenset and noticed
the following:

**code
#!/usr/bin/env python

from sets import ImmutableSet


class MSet1(ImmutableSet):
def __init__(self, iterArg, myName="foo"):
ImmutableSet.__init__(self, iterArg)
self.name = myName


class MSet2(frozenset):
def __init__(self, iterArg, myName="foo"):
frozenset.__init__(self, iterArg)
self.name = myName


m1 = MSet1([1,2,3], myName = "donkey")
print m1
print m1.name

m2 = MSet2([1,2,3], myName = "kong")
print m2
print m2.name
*end code**

*run**
MSet1([1, 2, 3])
donkey
Traceback (most recent call last):
  File "./setTest.py", line 22, in ?
m2 = MSet2([1,2,3], myName = "kong")
TypeError: frozenset() does not take keyword arguments
*end run

I'm missing something and couldn't find it in the docs.

Speaking of which, in the docs at the bottom of the description of the
builtin set/frozenset, there is a link to a page describing differences
between the builtin sets and the sets module sets.  This link is broken
locally and on the python.org docs.
Locally, it reads:
file:///usr/share/doc/python-docs-2.4.2/html/lib/module-comparison-to-builtin-set.html

While it should read:
file:///usr/share/doc/python-docs-2.4.2/html/lib/comparison-to-builtin-set.html

Regards,
Mark
-- 
http://mail.python.org/mailman/listinfo/python-list


[Ann] RO package 2005-10-31

2005-10-31 Thread Russell E. Owen
RO package 2005-10-31 is now available from


What is it?
A package of python utilities I wrote to support a telescope control 
interface. RO has a strong emphasis on the Tkinter GUI library, 
networking, astronomy and cross-platform support (unix, MacOS X and 
Windows). For more information, follow the link above.

Changes include:
- RO.DS9 is smarter about finding ds9 and xpa and can now handle 
byteswapped arrays.
- RO.Prefs now can map old pref names to new (allowing one to migrate a 
preference name).

For a full version history see:


-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: frozenset/subclassing/keyword args

2005-11-01 Thread Mark E. Fenner
> Without researching it, I would guess that you have to override __new__
> so as not to pass through the myName arg to the otherwise inherited and
> called-with-all-arguments __new__ of the base class. 



> Regards,
> Bengt Richter

Bengt,

Thanks as always!  Python's rabbit holes always go a little deeper then
you've currently gone.  My one irritation is that it seems that the error
message could give some indication of where the problem lies.  "bad args to
__new__", "immutable's bypass init", "black voodoo ahead" ... but I know,
efficiency, conciseness, other concerns, etc. etc.  Doesn't mean I can't
gripe about it!  

As you said, there are a number of threads on this.  Consulting those gave a
quick three line solution, shown below.

Regards,
Mark

P.S. Here's what I should have been doing:

 start file *
#!/usr/bin/env python

from sets import ImmutableSet

class MSet1(ImmutableSet):
def __init__(self, iterArg, myName="foo"):
ImmutableSet.__init__(self, iterArg)
self.name = myName



# works
class MSet2(frozenset):
def __new__(cls, itrarg, *args, **kwargs):
return frozenset.__new__(cls, itrarg)

def __init__(self, iterArg, myName="foo"):
frozenset.__init__(self, *iterArg)
self.name = myName

# broken
class MSet3(frozenset):
def __init__(self, iterArg, myName="foo"):
frozenset.__init__(self, *iterArg)
self.name = myName

m1 = MSet1([1,2,3], myName = "donkey")
print m1
print m1.name

m2 = MSet2([1,2,3], myName = "mario")
print m2
print m2.name

m3 = MSet3([1,2,3], myName = "kong")
print m3
print m3.name
*** end file 

* sample run **
MSet1([1, 2, 3])
donkey
MSet2([1, 2, 3])
mario
Traceback (most recent call last):
  File "./setTest.py", line 33, in ?
m3 = MSet3([1,2,3], myName = "kong")
TypeError: frozenset() does not take keyword arguments
** end run ***

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Tcl/Tk programmer learns Python--any advice?

2005-11-08 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 Kevin Walzer <[EMAIL PROTECTED]> wrote:

>I'm a Tcl/Tk developer who has been dabbling with Python for some time,...
>Well, I have finally found a good reason to learn Python in more depth:...
>
>Any advice, particularly from other programmers with a lot of experience
>in Tcl, is appreciated.

In Tkinter you don't name widgets to specify their hierarchy; instead 
when you create a new widget you specify it's parent. A tk name does get 
generated for you, but you'll never need it.

You can set and get properties on Tkinter widgets using dictionary 
notation:
curr_value = wdg["property_name"]
wdg["property_name"] = new_value
this is very convenient if you don't want to set a lot of properties at 
once.

Grid in Tkinter has less useful defaults than in tk. You should probably 
specify row and column when using Tkinter's gridder.

If you try to mix tk and Tkinter, beware of Tkinter objects that clean 
up after themselves. For instance a tkFont.Font object represents a 
named font in tk, but if you lose all references to it in python, the 
named font in tk is destroyed.

Features of Python that are well integrated and well worth using include:
- objects
- collection classes (including list, dict and set)
- exception handling
- default arguments for functions

tcl is a unusual in its desire to parse every string as a command. It 
has plusses and minuses, but in any case, you'll have to learn to do 
without (as you would when switching to almost any other language).

-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PythonMagick on Windows

2005-12-05 Thread Travis E. Oliphant
Adam Endicott wrote:
> Does anyone know anything about PythonMagick? I've got a project that
> could use ImageMagick, so I went looking around for PythonMagick, and
> I'm a bit lost.
> 
> I was able to download the PythonMagick source from the ImageMagick
> site, but I'm on Windows and don't have the ability to compile it. I
> found reference to a windows installer for PythonMagick on the wxPython
> wiki, but the links take me to procoders.net, which seems to have
> abandoned the project (at least I couldn't find anything to download).
> 
> So what's the state of this project?
> 
> Actually, I'm wondering if I would gain anything by using PythonMagick
> anyway. I'm going to be distributing a py2exe created executable that
> needs to do some image manipulation. Would I still need ImageMagick
> seperately installed on the client machine to use PythonMagick anyway?
> Or could it all be self contained? If I'd need to install ImageMagick
> on client machines anyway, I guess I can just use the commandline
> interface to ImageMagick from Python.
> 

There is a boost-less interface to imagemagick on the pylab project page 
at Sourceforge.   Last I checked it compiled for windows.  But, I 
haven't really played with it for a while.  You might find the old 
binaries there useful for at least some version of Image Magick.

http://sourceforge.net/project/showfiles.php?group_id=1315


-Travis Oliphant

-- 
http://mail.python.org/mailman/listinfo/python-list


directory bug on linux; workaround?

2005-01-13 Thread Russell E. Owen
I stumbled across a really strange bug involving directories on linux.

os.path.exists(path) can return 0 even after os.path.mkdir(path) 
succeeds (well after; this isn't a timing issue).

For the first file, the directory did not exist, so my code created the 
directory (successfully) using  os.path.mkdir(path). The next file 
failed because os.path.exists(path) returned false, so my code tried to 
create the directory again, which failed with "directory exists".

It seems that the path was to a "fat" file partition and included a 
directory name that was all uppercase. The directory was created, but 
using lowercase. I'm not yet sure the version of python.

The workaround for now is to not use fat file partitions. But I was 
wondering if anyone had a better option?

-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Configuring Python for Tk on Mac

2005-01-24 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Martyn Quick) wrote:

>On my desk here at work I have a Mac G4 running Mac OS X v10.2.8.
>
>When I go into a terminal and type "python" up comes a nice python
>interface and all seems great.  However when I type "import Tkinter"
>I'm greeted by the following error

Assuming you are running MacPython from 
...

Install Aqua Tcl/Tk as another poster suggested.

Run Applications/MacPython.../Package Manager and install Tkinter.

Or if your MacPython is out of date, you may just want to download and 
install the current version. If Tcl/Tk is already installed then I think 
it will install Tkinter automatically (but if not, use Package Manager).

If you are running some other python, please tell us more about it. (If 
it's fink python, install the version that includes Tkinter support, but 
this runs on X11 instead of Aqua).

-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter socket client ?

2005-01-24 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Tonino" <[EMAIL PROTECTED]> wrote:

>yeah - had a look at createfilehandler() - was a bit confusing - but
>your example helps ;)

Be warned that createfilehandler does not work on Windows, though it 
works well on unix and MacOS X.

So my suggestion is one to try any of these (any of which are preferable 
to threads):
- file handlers for non-Windows code
- use tcl sockets for cross-platform code.
- use Twisted Framework (some work to learn, but supposedly very solid; 
I confess I've never used it myself).

There is a bit of info on the first two options (including a link to the 
RO package that includes a python interface to tcl sockets) here:



-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter socket client ?

2005-01-25 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Tonino" <[EMAIL PROTECTED]> wrote:

>thanks for this info - I had to abandon the createfilehandler() method
>as it is not supported in windows and the GUI "might" be used there at
>some time ...
>
>So - I went the threading route - works well - for now - so I will
>stick to it ...
>
>BUT - the next question:
>In the Text() widget - why - when the text scrolls off the screen -
>does the window not follow it ?
>
>I have added a scrollbar to it :
>
>self.center_frame = Frame(self.top_frame, background="tan",
>relief=RIDGE)
>
>self.text=Text(self.center_frame,background='white')
>scroll=Scrollbar(self.center_frame)
>self.text.configure(yscrollcommand=scroll.set)
>
>self.text.pack(side=LEFT, fill=BOTH, expand=YES)
>scroll.pack(side=RIGHT,fill=Y)
>self.center_frame.pack(side=RIGHT, expand=YES, fill=BOTH)
>
>
>but the window does not scroll to follow the text ?
>Any ideas ?

That's just how it works. But when you append text you can easily tell 
the text widget to display it, e.g. using "see". Here is the code I use 
(from RO.Wdg.LogWdg.py), which has these useful features:
- auto-scrolls only if the user is already scrolled to the of text (so 
if a user is staring at some older data, it won't be jerked out from 
under them)
- deletes excess text.

def addOutput(self, astr, category=None):
"""Add a line of data to the log.

Inputs:
- astr: the string to append. If you want a newline, specify the \n 
yourself.
- category: name of category or None if no category
"""
# set auto-scroll flag true if scrollbar is at end
# there are two cases that indicate auto-scrolling is wanted:
# scrollPos[1] = 1.0: scrolled to end
# scrollPos[1] = scrollPos[0]: window has not yet been painted
scrollPos = self.yscroll.get()
doAutoScroll = scrollPos[1] == 1.0 or scrollPos[0] == scrollPos[1]
if category:
self.text.insert("end", astr, (category,))
else:
self.text.insert("end", astr)
extraLines = int(float(self.text.index("end")) - self.maxLineIndex)
if extraLines > 0:
self.text.delete("1.0", str(extraLines) + ".0")
if doAutoScroll:
self.text.see("end")

-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: continuous plotting with Tkinter

2005-02-03 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Martin Blume" <[EMAIL PROTECTED]> wrote:

>I have a number-crunching application that spits out 
>a lot of numbers. Now I'd like to pipe this into a python
>app and plot them using Tkinter, such as:
>$ number_cruncher | myplot.py
>But with Tkinter once  I call Tkinter's mainloop() I
>give up my control of the app and I can't continue to
>read in data from stdin.  Or can I? If so, how?

One way is to use a thread to read the numbers, then make them available 
to the main thread via a Queue object, which you poll for new values.

Another option is to use a Tk-compatible file or socket of some kind 
which triggers a callback when data comes in. See 
 
some ideas on this.

-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reinstall python 2.3 on OSX 10.3.5?

2005-02-03 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

>Hi there
>
>I started a very long and roundabout process of attempting to install
>python 2.3.4 along side my apple-installed 2.3 system. To make a long
>story short, I have completely confabulated my environment ( i deleted
>the 2.3 binaries and so forth from the system in an attempt to start
>things fresh), and now I cannot figure out how to reinstall the base
>2.3 Apple python distribution.
>Can somebody please point me in the right direction?

Archive and Install of the operating system is the safest.

But if you have some kind a backup or know somebody with a similar Mac, 
you could try reinstalling /System/Library/Frameworks/Python.framework. 
You'd have to do this in a way that preserved ownership and permissions.
That would probably still leave a few unresolved symbolic links and/or 
aliases lying around, but is worth a try (especially if you can examine 
that system and see where the links go). In particular 
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/s
ite-packages" points to "/Library/Python/2.3" and /usr/bin/python and 
/usr/bin/pythonw point somewhere useful.

But...archive and install is really the safest and it's a chance to 
clean up a bit of cruft. (But it messes with /usr/local and your web 
site, so back all that up first).

-- Russell

P.S. I installed a separate unix/x11 Python 2.4 in /usr/local with no 
problem using the default install process. However, I wanted X11 Tk 
support for that, so I first:
- moved the aqua Tk (in /Library/Frameworks/Tk.framework, and 
Tcl.framework) so the installers could not find them
- installed unix/x11 tcl and tk (again using the default install process)
This results in a perfectly workable python that uses the X11 Tk stuff.

It's a minor headache having two pythons -- every package has to be 
installed twice if you want it available in both pythons.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python scripts a PC Interfacing equipment

2005-02-06 Thread Pramode C E
Hello,

The Phoenix project aims to bring low cost PC-based experimental
Physics to the classroom. Read a short intro here:

http://linuxgazette.net/111/pramode.html


Regards,
Pramode
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How long is a piece of string? How big's a unit?

2005-07-11 Thread Chuck E. Cheese
The correct answer to the above question

How long is a piece of string? 

is 

2 times half it's length


CEC

-- 
http://mail.python.org/mailman/listinfo/python-list


"Aliasing" an object's __str__ to a different method

2005-07-22 Thread Jeffrey E. Forcier
I am attempting to write a class whose string representation changes  
in response to external stimuli. While that effect is obviously  
possible via other means, I attempted this method first and was  
surprised when it didn't work, so I now want to know why :)

Given the following class definition:

class MyClass(object):

 def Edit(self):
 return "I, %s, am being edited" % (self)

 def View(self):
 return "I, %s, am being viewed" % (self)

 def setEdit(self):
 self.__str__ = self.__repr__ = self.Edit

 def setView(self):
 self.__str__ = self.__repr__ = self.View


...I would expect the following behavior:

In [130]: testObject = MyClass()
In [131]: testObject.setEdit()
In [132]: str(testObject)
Out[132]: 'I, <__main__.MyClass object at 0x511270>, am being edited'


Unfortunately, this is what happens instead:

In [130]: testObject = MyClass()
In [131]: testObject.setEdit()
In [132]: str(testObject)
Out[132]: '<__main__.MyClass object at 0x511270>'


In other words, str() is _NOT_ apparently calling .__str__ as  
it's supposed to! However, calling __str__ directly (which, yes,  
you're not supposed to do) does work as expected:

In [133]: testObject.__str__()
Out[133]: 'I, <__main__.MyClass object at 0x511270>, am being edited'


Now, my understanding is that functions/methods are first-order  
objects, and can be pointed to via reference, and that appears to be  
true:

In [135]: def func1():
.: print "I'm func1"
.:
In [136]: def func2():
.: print "I'm func2"
.:
In [137]: func2 = func1
In [138]: func2()
I'm func1


However, expressions such as self.__str__ =   
aren't working for me, as above. Why not?

Thanks for any responses,
Jeff

--
Jeffrey E. Forcier
Junior Developer, Research and Development
Stroz Friedberg, LLC
15 Maiden Lane, 12th Floor
New York, NY 10038
[main]212-981-6540 [direct]212-981-6546
http://www.strozllc.com

This message is for the named person's use only.  It may contain
confidential, proprietary or legally privileged information. No right to
confidential or privileged treatment of this message is waived or lost
by any error in transmission.  If you have received this message in
error, please immediately notify the sender by e-mail or by telephone at
212.981.6540, delete the message and all copies from your system and
destroy any hard copies.  You must not, directly or indirectly, use,
disclose, distribute, print or copy any part of this message if you are
not the intended recipient.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Aliasing" an object's __str__ to a different method

2005-07-22 Thread Jeffrey E. Forcier
On Jul 22, 2005, at 7:46 PM, Michael Hoffman wrote:

> I'm too tired and/or lazy to check, but I believe str() is calling
> MyClass.__str__(testObject) as it is supposed to rather than
> testObject.__str__() as you say it is supposed to. ;-)
>
> Someone else or Google can probably enlighten you on the reason for  
> this
> better than I. I think this is something that is not explained very  
> well
> in the docs, which do say that a class implements special method  
> names,
> but doesn't make it very clear that an object can't always override  
> them.
>
> If you redirect to a second method you can overwrite on the  
> instance, I
> think you will get the results you want.
> -- 
> Michael Hoffman
> -- 
> http://mail.python.org/mailman/listinfo/python-list
>

So in other words, __str__() and its ilk are class methods instead of  
instance methods? The documentation appears to contradict this:

(http://python.org/doc/2.4/ref/specialnames.html)
"For instance, if a class defines a method named __getitem__(), and x  
is an instance of this class, then x[i] is equivalent to x.__getitem__ 
(i)."


However, you appear to be correct, and the docs appear to be confused:

class MyClass(object):

 def edit(self):
 return "I'm in edit mode"

 def setToEdit(self):
 MyClass.__str__ = self.edit

In [3]: test = MyClass()
In [4]: str(test)
Out[4]: '<__main__.MyClass object at 0x2d21d0>'
In [5]: test.setToEdit()
In [6]: str(test)
Out[6]: "I'm in edit mode"


Of course, this doesn't quite do what I had in mind, and in fact you  
could say it's kinda sloppy, binding an ostensibly static class  
method to an instance method:

In [7]: repr(MyClass.__str__)
Out[7]: '>'


Either way, guess I will have to take another route. Your suggestion  
is what I'd had in mind, and does the job pretty well. I'm still  
attempting to figure out the best approach to my overall problem,  
however, so who knows where I will end up =)

Thanks for the response! If you or anyone else can shed some insight  
on *why* this is the way it is (and why/if the docs are in fact  
incorrect) I'd appreciate further replies. More knowledge == better.

Regards,
Jeff

--
Jeffrey E. Forcier
Junior Developer, Research and Development
Stroz Friedberg, LLC
15 Maiden Lane, 12th Floor
New York, NY 10038
[main]212-981-6540 [direct]212-981-6546
http://www.strozllc.com

This message is for the named person's use only.  It may contain
confidential, proprietary or legally privileged information. No right to
confidential or privileged treatment of this message is waived or lost
by any error in transmission.  If you have received this message in
error, please immediately notify the sender by e-mail or by telephone at
212.981.6540, delete the message and all copies from your system and
destroy any hard copies.  You must not, directly or indirectly, use,
disclose, distribute, print or copy any part of this message if you are
not the intended recipient.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Aliasing" an object's __str__ to a different method

2005-07-23 Thread Jeffrey E. Forcier
Thanks for all the additional replies thus far!

Apparently the issue, as stated implicitly or explicitly by most of  
you, is that new-style class instances essentially defer their magic  
methods to the class's static versions of same. This is good to know :)

Ironically, the reason I'm using new-style classes is that I only  
read up on them very recently, and was attempting to get myself into  
the habit of inheriting from 'object' by default. Go figure.

Anyway, to take a step back, the *actual* actual reason for my  
investigation into this issue is that I'm attempting to create a  
collection of classes representing HTML page/form elements, many of  
which are represented differently depending on whether they're in a  
"view" or "edit" state.

And ideally I wanted to be able to hold a collection of these objects  
and toggle them all to one state or the other, then bandy them about  
as if they were strings, e.g. mixing them with literal strings via str 
(obj).

Clearly there are at least a handful of ways to accomplish this, but  
the one that came to mind first was, as I said at the beginning, to  
define both behaviors on each object and then have the ability to  
point __str__ to one or the other. I suppose now I need to figure out  
which is more important, that ease-of-use of overriding __str__ or  
whatever benefits new-style classes give (something I'm still a bit  
unclear on).

Thanks again,
Jeff

--
Jeffrey E. Forcier
Junior Developer, Research and Development
Stroz Friedberg, LLC
15 Maiden Lane, 12th Floor
New York, NY 10038
[main]212-981-6540 [direct]212-981-6546
http://www.strozllc.com

This message is for the named person's use only.  It may contain
confidential, proprietary or legally privileged information. No right to
confidential or privileged treatment of this message is waived or lost
by any error in transmission.  If you have received this message in
error, please immediately notify the sender by e-mail or by telephone at
212.981.6540, delete the message and all copies from your system and
destroy any hard copies.  You must not, directly or indirectly, use,
disclose, distribute, print or copy any part of this message if you are
not the intended recipient.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Aliasing" an object's __str__ to a different method

2005-07-24 Thread Jeffrey E. Forcier
On Jul 24, 2005, at 5:00 AM, Bengt Richter wrote:

> Actually, it's not just the "magic" methods. [...]

Thanks for the clarification/explanation =)

> This looks a little strange because the repr of the bound method  
> includes a repr of the thing bound to,
> which returns the Edit/View presentation (after the 'of' above).
> (A possible reason to consider using just __str__ and letting  
> __repr__ be).

Yea, I must apologize, I pasted in a slightly different version of  
the class in my original email than I intended to...I fully  
understand the difference between __str__ and __repr__ and that bit  
of code where I attempted to bind to both was me attempting to  
discern exactly what was going on. The "real" version would only be  
binding to __str__ and leaving __repr__ alone so it could be used as  
intended =)

> A function's __get__ method will deliver a bound method if the lookup
> is via an inst, or an unbound method if the lookup is via the  
> class, in which
> case None is passed to __get__ instead of the instance.
>
> The upshot is that you can create descriptors __str__ and  
> __repr__for your class that will
> return bound methods using __str__ and __repr__ function attributes  
> of your instance (if they exist)
> instead of the normal class attributes, and we can chose from  
> several normal class attributes according
> to a general mode flag of the class.

[big-arse snip of code/output]

I half-understood this and what followed, but that's my fault and not  
that of your explanation. Honestly, I'm still trying to elevate my  
Python knowledge from a primarily quick-scripting level to one  
suitable for larger applications (or at least, more intelligent  
scripts =)). Specifically with things like descriptors and their ilk,  
I need to reread the various docs and PEPs out there.

But, thanks for the detailed example, and you can be sure I'll return  
to it in the near future after some more reading.


> You could use this kind of thing in a base class and specialize
> in subclasses to override stuff, and you can do other stuff too.
> Your choices are more varied that you probably thought ;-)

Oh, I know there's a whole host of ways to accomplish this, I just  
tend to get narrowly focused on a single option or couple of options  
for stretches of time, heh.

>> And ideally I wanted to be able to hold a collection of these objects
>> and toggle them all to one state or the other, then bandy them about
>>
>  ^^^
> does that mean all instances with a single toggling action, or each
> individually? You could have both. I.e., a general mode flag and the
> ability to assign an arbitrary __str__ and/or __repr__ override for
> a particular instance. See example, where all are toggled by default.

Well, either, depending on how flexible I want the overall design to  
be, but primarily all at once. E.g. I'd have a Page or PageBody  
container class holding a bunch of (implementing the same interface)  
objects as discussed, and would want all of those sub-objects to be  
in the same mode. In other words...a page is either displaying text  
fields for editing, or plain text for display (but with myriad form  
elements, not just text fields, of course).


Thanks again,
Jeff

--
Jeffrey E. Forcier
Junior Developer, Research and Development
Stroz Friedberg, LLC
15 Maiden Lane, 12th Floor
New York, NY 10038
[main]212-981-6540 [direct]212-981-6546
http://www.strozllc.com

This message is for the named person's use only.  It may contain
confidential, proprietary or legally privileged information. No right to
confidential or privileged treatment of this message is waived or lost
by any error in transmission.  If you have received this message in
error, please immediately notify the sender by e-mail or by telephone at
212.981.6540, delete the message and all copies from your system and
destroy any hard copies.  You must not, directly or indirectly, use,
disclose, distribute, print or copy any part of this message if you are
not the intended recipient.

-- 
http://mail.python.org/mailman/listinfo/python-list


Time formatting and date suffixes

2005-07-25 Thread Jeffrey E. Forcier
This seems like a dead simple question, as it's so rudimentary I  
can't believe it hasn't been addressed before. I'm using the  
time.strftime() function (actually the mxDateTime implementation, but  
they're compatible so it shouldn't matter) to spit out fairly basic  
date formats, to wit:

January 25th, 2005

The various and sundry date objects in both mxDateTime and Python  
proper's time/datetime don't seem to have anything anywhere dealing  
with the 'th' suffix on the date. So in other words, I can use  
strftime() to get 'January 25, 2005' but don't see anything dealing  
with outputting the suffixes like 'th', 'nd' and the like. Googling  
around and searching this list's archives aren't turning anything up,  
either.

Am I missing something obvious, or is it just really, really frowned  
upon to use such a locale-specific function as English date suffixes?

Thanks,
Jeff

--
Jeffrey E. Forcier
Junior Developer, Research and Development
Stroz Friedberg, LLC
15 Maiden Lane, 12th Floor
New York, NY 10038
[main]212-981-6540 [direct]212-981-6546
http://www.strozllc.com

This message is for the named person's use only.  It may contain
confidential, proprietary or legally privileged information. No right to
confidential or privileged treatment of this message is waived or lost
by any error in transmission.  If you have received this message in
error, please immediately notify the sender by e-mail or by telephone at
212.981.6540, delete the message and all copies from your system and
destroy any hard copies.  You must not, directly or indirectly, use,
disclose, distribute, print or copy any part of this message if you are
not the intended recipient.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Time formatting and date suffixes

2005-07-25 Thread Jeffrey E. Forcier
See, I was thinking I'd have to write a short function to do it myself,
but I hadn't realized it could be quite *that* short. Thanks! That'll
do quite nicely, and is definitely something I'm going to throw in my
"general utility functions" folder :)

Regards,
Jeff

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlobject vs mysqldb module

2005-08-09 Thread Jeffrey E. Forcier
Skip is correct, they're somewhat different:

SQLObject is an 'ORM' or 'Object-Relational Mapping', meaning that it
allows you to handle everything related to the database with objects.
The table handles are objects, the result set is an object, the
individual rows in a result set are objects with attributes for the
fields/columns. So instead of "SELECT id,name FROM people WHERE
location='New York'", you'd do something like the following:

for row in People.selectBy(location='New York'):
print "id: %s, name: %s" % (row.id,row.name)

This is nice if you value object-oriented code very highly, and don't
have any specific SQL-level tricks you wish to employ (although
SQLObject can handle those as well, I'm told, it's just not its main
function).

MySQLDB, while I haven't used it specifically, is probably similar to
its Postgres cousins pyPgSQL and psycopg, in that it just provides a
Python DB API compliant interface to the database (see
http://www.python.org/peps/pep-0249.html).

Such modules do not provide much or any object orientation, sticking
with a more low-level approach of making SQL calls and getting
dictionaries back, to wit:

conn = [module_name].connect(connection_args)
cursor = conn.cursor()
cursor.execute("SELECT id,name FROM people WHERE location='New York'")
print cursor.fetchall()


Anyway, sorry if that's over your head (it's hard to tell your
experience level from your post), but the basic gist is that SQLObject
is good for a higher-level and very easy-to-use database connection,
and MySQLDB is probably good if you're very comfortable with SQL and
not so much with object-oriented programming (or if you have any other
reason to prefer straight SQL queries).

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recommendations for CVS systems

2005-08-09 Thread Jeffrey E. Forcier
Thirding the Subversion/SVN suggestions. It's generally a newer, better
CVS with some new features and a lot less of the negative features/lack
thereof, of the older system.

If any of your team has CVS experience they should have no real problem
with the switch, and anyone without prior version control experience
will just be that much better off starting with Subversion.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: epyDoc Questions

2005-08-11 Thread Jeffrey E. Forcier
Neil Benn wrote:
>1. I want to document the attributes (instance and also class) of a
>   class and or module, I know the tags are there - where does they
>   go (before/after theclass decleration, top of the module, if
>   someone puts in the class doc but misses out the module stuff, how
>   will epydoc know that this is meant to be class and not module
>   (although someone doing this will probably get shouted at in a
>   code review!)?

http://epydoc.sourceforge.net/fields.html

You specify different tags for class, instance and module level
attributes/variables using the respective tags @cvar, @ivar and @var. I
believe you need to put @cvar and @ivar in the class' docstring, as
follows:


## code ##
class MyClass():
"""
Stuff.

@cvar varOne: the first var
@cvar varTwo: the second var
"""
varOne = 1
varTwo = 2
[...]
## end code ##

And @var should probably be used in the module's top level docstring in
the same manner.


>2. In the argument to the tag for raises, how can I put a link
>   through to the exception?

Not 100% sure on this one; I would imagine that Epydoc would
automatically put those links in for you? Otherwise I don't believe L{}
can be used in the field name, only in the field text/body paragraph.

>3. How would I go about marking up the property docs so that it knows
>   what the setter and getter methods are - it links through to the
>   methods but the docs arn't in there, they are in the fifth
>   argument to the property method (I can manually do this using
>   sections but is there a tag I can use?)

Like a previous poster said, can you show us an example? I don't quite
follow this one :)

HTH,
Jeff

-- 
http://mail.python.org/mailman/listinfo/python-list


Sep 9 is the last day for reduced rates for OOPSLA 2005

2005-08-16 Thread Gail E. Harris

OOPSLA 2005 is being held in San Diego, Oct 16 to 20.

Invited speakers include:
 Robert Hass, Martin Fowler, Gerald Jay Sussman
 Grady Booch, Jimmy Wales, Mary Beth Rosson, David P. Reed

The conference features 29 research papers, 58 tutorials by leaders in  
their fields, 23 Workshops, 5 Panel discussion sessions, 9 Practitioner  
reports, Onward!, DesignFest, Lightning Talks, Posters, Demonstrations, 4  
special symposia, and more...

There is also a contest for promoting OOPSLA where you can win a suite for  
the conference week.

More details are available at www.oopsla.org.


-- 
Gail E. Harris, MSc, PMP
Principal, Solution Delivery & Emerging Technology
Instantiated Software Inc.
http://www.Instantiated.CA
[EMAIL PROTECTED]
(416) 573-0469

DISCLAIMER:   The information contained in this e-mail may be confidential  
and is intended solely for the use of the named addressee. Access, copying  
or re-use of the e-mail or any information contained therein by any other  
person is not authorized.  If you are not the intended recipient please  
notify us immediately by returning e-mail to the originator.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to get a unique id for bound methods?

2005-08-19 Thread Russell E. Owen
I have several situations in my code where I want a unique identifier 
for a method of some object (I think this is called a bound method). I 
want this id to be both unique to that method and also stable (so I can 
regenerate it later if necessary).

I thought the id function was the obvious choice, but it doesn't seem to 
work. The id of two different methods of the same object seems to be the 
same, and it may not be stable either. For instance:

class cls(object):
  def __init__(self):
print id(self.meth1)
print id(self.meth2)
  def meth1(self):
pass
  def meth2(self):
pass

c = cls()
3741536
3741536
print id(c.meth1)
3616240
print id(c.meth2)
3616240

I guess that just means bound methods aren't objects in their own right, 
but it surprised me.

The "hash" function looks promising -- it prints out consistent values 
if I use it instead of "id" in the code above. Is it stable and unique? 
The documentation talks about "objects" again, which given the behavior 
of id makes me pretty nervous.

Any advice would be much appreciated.

-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get a unique id for bound methods?

2005-08-19 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 Benji York <[EMAIL PROTECTED]> wrote:

>Russell E. Owen wrote:
>> The id of two different methods of the same object seems to be the 
>> same, and it may not be stable either.
>
>Two facts you're (apparently) unaware of are conspiring against you:
>
>1) the "id" of an object is consistent for the lifetime of the object, 
>but may be reused after the object goes away
>
>2) methods are bound on an as-needed basis and then normally discarded 
>(unless you do something to keep them around)

Thank you and Bengt Richter. You both explained it very well.

The current issue is associated with Tkinter. I'm trying to create a tk 
callback function that calls a python "function" (any python callable 
entity).

To do that, I have to create a name for tk that is unique to my python 
"function". A hash-like name would be perfect, meaning a name that is 
always the same for a particular python "function" and always different 
for a different python "function". That would save a lot of housekeeping.

Does the built-in hash function actually do the job?

If I centralize all tk callback management and keep objects that 
represent the tk callback around then I can avoid the whole issue. I was 
hoping to avoid that, because it complicates housekeeping and adds a 
risk of memory leaks (at least I think so; right now tk deallocates its 
callback functions in the few cases I care about so I don't worry about 
it.)

-- Russell

P.S. Paolino: thank you also for your kind reply. Your suggestion sounds 
very useful if I only want a hash for a bound function, but in this case 
since I want a hash for any callable entity I'm not sure it'll work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Decorator and Metaclasses Documentation

2005-08-21 Thread Jeffrey E. Forcier
Amusingly, I was just perusing these links earlier today. Go go Firefox
history search!

http://www.python.org/2.2/descrintro.html
http://users.rcn.com/python/download/Descriptor.htm

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Decorator and Metaclasses Documentation

2005-08-21 Thread Jeffrey E. Forcier
Sorry about that, I misread the original question. However, the
python.org link is still valid as it concerns metaclasses as well as a
handful of other topics.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get a unique id for bound methods?

2005-08-22 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Bengt Richter) wrote:

>On Fri, 19 Aug 2005 16:33:22 -0700, "Russell E. Owen" <[EMAIL PROTECTED]> 
>wrote:
>[...]
>>
>>The current issue is associated with Tkinter. I'm trying to create a tk 
>>callback function that calls a python "function" (any python callable 
>>entity).
>>
>>To do that, I have to create a name for tk that is unique to my python 
>>"function". A hash-like name would be perfect, meaning a name that is 
>>always the same for a particular python "function" and always different 
>>for a different python "function". That would save a lot of housekeeping.
>>
>Why do you need a name? Can you post an example snippet that shows
>a callback function being used with Tkinter as you would wish?
>I have a feeling there is a much simpler solution than you are imagining ;-)

Here is an example (simplified from my real code; I may have introduced 
an error in the process). I could switch to the twisted framework, but 
this code has been working very well and it saves my users from having 
to install a 3rd party package.

-- Russell

def addTkCallback(tk, func):
tkName = "cb%d" % hash(func)
tk.createcommand(tkNname, func)
return tkName

class TkSocket(TkBaseSocket):
def __init__(self,
addr,
port,
binary=False,
readCallback = None,
stateCallback = None,
tkSock = None,
):
...
try:
# create the socket and configure it
self._sock = self._tk.call("socket", ...)
self._tk.call("fconfigure", self._sock, ...)

# add callbacks; the write callback is just used to detect 
state
readName =addTkCallback(self._tk, self._doRead)
self._tk.call('fileevent', self._sock, "readable",
readName)
    connName = addTkCallback(self._tk, self._doConnect)
self._tk.call('fileevent', self._sock, "writable", connName
except Tkinter.TclError, e:
raise RuntimeError(e)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: High Level FTP library

2005-08-23 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Paulo Pinto" <[EMAIL PROTECTED]> wrote:

>Hello,
>
>Is there any Python library similar to NET::FTP from Perl?
>ftplib seems too lowlevel.
>
>I already found a few, but would like to get one that is
>endorsed by the community.

Try urllib or urllib2; these are included with python. urllib2 is newer 
but only works for anonymous ftp. Caveat: I ran into trouble doing 
multiple simultaneous ftp using urllib. I have not used urllib2.

Another possibility is Twisted Framework. It has a bit of a learning 
curve but is well regarded. If you plan to do a lot with networking you 
should definitely check it out.

-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get a unique id for bound methods?

2005-08-23 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

>Russell E. Owen wrote:
>
>>>>The current issue is associated with Tkinter. I'm trying to create a tk
>>>>callback function that calls a python "function" (any python callable
>>>>entity).
>>>>
>>>>To do that, I have to create a name for tk that is unique to my python
>>>>"function". A hash-like name would be perfect, meaning a name that is
>>>>always the same for a particular python "function" and always different
>>>>for a different python "function". That would save a lot of housekeeping.
>
>have you tried Tkinter's built-in _register method?
>
>>>> import Tkinter
>>>> w = Tkinter.Tk()
>>>> help(w._register)
>Help on method _register in module Tkinter:
>
>_register(self, func, subst=None, needcleanup=1) method of Tkinter.Tk 
>instance
>Return a newly created Tcl function. If this
>function is called, the Python function FUNC will
>be executed. An optional function SUBST can
>be given which will be executed before FUNC.

Thanks. That looks like just the thing. I think I had seen it but was 
deterred by the leading underscore (suggesting an internal method whose 
interface might change). Still, I guess if it gets modified I can just 
change my code.

-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get a unique id for bound methods?

2005-08-23 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

>Russell E. Owen wrote:
>
>>>>The current issue is associated with Tkinter. I'm trying to create a tk
>>>>callback function that calls a python "function" (any python callable
>>>>entity).
>>>>
>>>>To do that, I have to create a name for tk that is unique to my python
>>>>"function". A hash-like name would be perfect, meaning a name that is
>>>>always the same for a particular python "function" and always different
>>>>for a different python "function". That would save a lot of housekeeping.
>
>have you tried Tkinter's built-in _register method?
>
>>>> import Tkinter
>>>> w = Tkinter.Tk()
>>>> help(w._register)
>Help on method _register in module Tkinter:
>
>_register(self, func, subst=None, needcleanup=1) method of Tkinter.Tk 
>instance
>Return a newly created Tcl function. If this
>function is called, the Python function FUNC will
>be executed. An optional function SUBST can
>be given which will be executed before FUNC.

Having looked at it again, it is familiar. I copied it when I wrote my 
own code. I avoided using at the time both because the initial 
underscore suggested it was a private method and because it introduces 
an extra function call.

_register has the same weakness that my code had when I used id(func) -- 
it uses the id of the function to generate the unique tk function name, 
but it keeps no reference to that function.

Either Tkinter is clever about keeping a reference to each callable 
around, or else it has the same bug I was seeing and it just doesn't 
show up often enough to have been caught. I should take some time and 
look into that.

It's a frustrating problem. There should be some simple way to get a 
unique hash-like identifier for any callable entity. If one were just 
using functions then id() would be fine. But bound methods are too 
different.

I'll use "hash" for now, but given that I"m not sure what hash is even 
doing, I should recode to something that I know works.

-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorta noob question - file vs. open?

2005-08-23 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 Peter A. Schott <[EMAIL PROTECTED]> wrote:

>Been reading the docs saying that file should replace open in our code, but 
>this
>doesn't seem to work:
>
># Open file for writing, write something, close file
>MyFile = file("MyFile.txt", "w")
>MyFile.write("This is a test.")
>MyFile.close()

This should work in a sufficiently recent version of python (I'm hedging 
because I don't recall when file was introduced -- python 2.2? 2.3?). 
What version are you using? What error do you see?

-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get a unique id for bound methods?

2005-08-24 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

>Russell E. Owen wrote:
>
>> Having looked at it again, it is familiar. I copied it when I wrote my
>> own code. I avoided using at the time both because the initial
>> underscore suggested it was a private method and because it introduces
>> an extra function call.
>>
>> _register has the same weakness that my code had when I used id(func) -- 
>> it uses the id of the function to generate the unique tk function name,
>> but it keeps no reference to that function.
>>
>> Either Tkinter is clever about keeping a reference to each callable
>> around, or else it has the same bug I was seeing and it just doesn't
>> show up often enough to have been caught. I should take some time and
>> look into that.
>
>of course it keeps a reference to it; how else do you expect
>the Tcl command to find the right PyObjects?

Right. Of course.

I started out emulating the code for _register but over time made 
various incremental changes. Eventually I messed up and started taking 
the id of the wrong thing. I was able to fix that and all is well -- 
without having to use the mysterious hash function.

I also now keep a reference to the tk function name so I can properly 
delete it when finished. That eliminates a small memory leak.

Thanks for all your help.

-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


Printing w/o newlines inside loops - odd behavior

2005-09-13 Thread Jeffrey E. Forcier
This is a difficult issue to search for, and Googling (and reviewing
the pertinent Python docs) has not found me anything useful. It's also
not a super important issue, but regardless of whether it's avoidable,
I still want to know what the heck is going on.

Doing multiple print statements inside a for loop, using the 'comma at
the end eats the newline' variant, results in zero output until the
loop completes its entire iteration.

def test():
   print "testing:",
   for x in range(10):
   time.sleep(1)
   print ".",
   print "done."

Executing test() results in the behavior described above. If one
removes the commas after the first two print statements, it behaves
normally, with "testing" showing up right away, then a period on each
newline every second until the end.

I've tried various things--os.system('sleep 1') instead of
time.sleep(1), sys.stdout.write() instead of print-with-a-comma, and
other equally silly tactics, to no avail.

What's going on here?

Thanks,
Jeff

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Printing w/o newlines inside loops - odd behavior

2005-09-13 Thread Jeffrey E. Forcier
Erik: Thanks, that was it!  Figured it was something along those lines,
but like I said, I didn't know specifically what was going on or what
to look for.

Larry: That recipe could be useful, thanks a lot :)

And thanks for the quick replies, too, you guys are awesome.

Regards,
Jeff

-- 
http://mail.python.org/mailman/listinfo/python-list


Python in XCode - autoindent?

2005-09-19 Thread Jeffrey E. Forcier
Hoping at least some of you use XCode...

In futzing with PyObjC and Cocoa programming on my Mac, I've come to
know XCode a little better, and am considering switching to it from my
existing editor (TextMate). However, it appears to lack your typical
auto-indenting that I'm sure most of you also find indispensable, e.g.
hitting Return after a 'def', 'class', 'if' etc results in an automatic
indentation.

Has anyone found a way to get this working? Google's not helping, and
while XCode does have intendation preferences, they either don't work
for Python syntax (even though the CodeSense, highlighting and so forth
work fine with the language) or I've still got something set wrong.

Thanks,
Jeff

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to define a window's position (Tkinter)

2005-02-28 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Harlin Seritt" <[EMAIL PROTECTED]> wrote:

>I am trying to use the geometry() method with the toplevel window
>called root. I know that one can do the following:
>
>root.geometry('400x400+200+200')
>
>This will put the window in 200, 200 position with a size of 400x400.
>Now, I don't really want to set the size. I simply want to set the
>position of the window. I've tried this:
>
>root.geometry('200+200')
>
>However, this doesn't seem to work. What can I do to set the position
>of the window without actually setting the size?

You were almost there, but you need an initial "+":
root.geometry("+200+200").

-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lisp-likeness

2005-03-15 Thread Steven E. Harris
Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> writes:

> BTW, the fact that a closure refers to a variable itself rather to its
> current value can be used to check the true attitude of languages with
> respect to functional programming, by observing how they understand
> their basic loops :-)

The thread "Midfunction Recursion"¹ from October 2002 sounds relevant
here, exploring options for bindings in iteration.


Footnotes: 
¹ 
http://groups-beta.google.com/group/comp.lang.lisp/browse_frm/thread/46bb18e56cad/0590de10f975a059

-- 
Steven E. Harris
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter shell problem

2004-11-29 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 "Philippe C. Martin" <[EMAIL PROTECTED]> wrote:

>Hi,
>
>I have the following problem:...
>If I trap (an exception), I do not get the stack dump that I which I would 
>show.
>...
>If I don"t trap it, then my clean up code...does not get called...
>
>Yet Idle manages - any clue ?

Use the traceback module. For example:

try:
...code to protect...
except (SystemExit, KeyboardInterrupt):
raise
except Exception, e:
traceback.print_exc(file=sys.stderr)
code to handle exception...

if you are sure none of your code can raise error exceptions that 
inherit directly from Exception, you can simplify this to one except:
except StandardError, e:
Unfortunately, some common modules (including Tkinter) raise exceptions 
that inherit from Exception, not StandardError.

-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PHP vs. Python

2004-12-22 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

>Anyone know which is faster?  I'm a PHP programmer but considering
>getting into Python ... did searches on Google but didn't turn much up
>on this.

For web service, the first hurdle is picking which python web interface 
to use, installing it and (if necessary) configuring your web server to 
use it. (All that choice is great in many respects, but it does 
complicate getting started.)

Anyway, once you've done that, i doubt you'll find any speed issues with 
python, and it is a more pleasant language than PHP. (Unfortunately, 
that initial hurdle can be a big one; I am still using PHP on my server 
because I never cleared it.)

-- Russell
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >