refering to base classes

2006-08-29 Thread glenn
hi - Im quite new to python, wondering if anyone can help me understand
something about inheritance here. In this trivial example, how could I
modify the voice method of 'dog' to  call the base class 'creatures'
voice method from with in it?

class creature:
def __init__(self):
self.noise=""
def voice(self):
return "voice:" + self.noise

class dog(creature):
def __init__(self):
self.noise="bark"

def voice(self):
print "brace your self:"

thanks
glenn

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


Re: refering to base classes

2006-08-29 Thread glenn

Chaz Ginger wrote:

> Chaz Ginger wrote:
> > glenn wrote:
> >> hi - Im quite new to python, wondering if anyone can help me understand
> >> something about inheritance here. In this trivial example, how could I
> >> modify the voice method of 'dog' to  call the base class 'creatures'
> >> voice method from with in it?
> >>
> >> class creature:
> >> def __init__(self):
> >> self.noise=""
> >> def voice(self):
> >> return "voice:" + self.noise
> >>
> >> class dog(creature):
> >> def __init__(self):
> >> self.noise="bark"
> >>
> >> def voice(self):
> >> print "brace your self:"
> >>
> >> thanks
> >> glenn
> >>
> > Try this:
> >
> > class dog(creature):
> > .
> > def voice(self):
> > print "brace your self:"
> > creature.voice(self)
> >
> > This should do it.
> I did forget to mention that in 'dog"s' __init__ you had better call
> creature's __init__. You might make it look like this:
>
> def __init__(self):
>   self.noise = 'bark'
>   creature.__init__(self)
>
> There is another approach - using Superclass - but I will leave that
> exercise to the reader.
first tip worked - funny thing was I =thought= I done that, but clearly
not - so thanks was going mad.
Superclass?... ok will look into this
thanks for reply(s)
Glenn

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


Re: refering to base classes

2006-08-29 Thread glenn

Bruno Desthuilliers wrote:

> glenn wrote:
> > hi - Im quite new to python, wondering if anyone can help me understand
> > something about inheritance here. In this trivial example, how could I
> > modify the voice method of 'dog' to  call the base class 'creatures'
> > voice method from with in it?
> >
> > class creature:
> > def __init__(self):
> > self.noise=""
> > def voice(self):
> > return "voice:" + self.noise
> >
> > class dog(creature):
> > def __init__(self):
> > self.noise="bark"
> >
> > def voice(self):
> > print "brace your self:"
>
>
> 
> It might be better to use newstyle classes if you can. Also, the
> convention is to use CamelCase for classes names (unless you have a
> strong reason to do otherwise).
> 
>
> Here you could use a class attribute to provide a default:
>
> class Creature(object):
>   noise = ""
>
>   def voice(self):
> return "voice:" + self.noise
>
>
> class Dog(Creature):
>   noise="bark"
>
>   def voice(self):
> print "brace your self:"
> return Creature.voice(self)
> # can also use this instead, cf the Fine Manual
> return super(Dog, self).voice()
>
> My 2 cents
ohh - interesting. Thanks for the camelCase tip - dont have a good
reason to do otherwise, just bad habits.
so for your $.02 do you see this as being, umm, superior in anyway to
creature.voice()?

glenn


> --
> bruno desthuilliers
> python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
> p in '[EMAIL PROTECTED]'.split('@')])"

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


Re: refering to base classes

2006-08-29 Thread glenn
Hi Roberto
> If you want dog.voice() to just print "voice: bark", you just have to omit
> the voice method for the dog class: it will be inherited from creature.
>
I would have thought this would be correct, but in this case, plus in
others im playin with, I get this issue:
---
given animal.py is:
class creature:
def __init__(self):
self.noise=""
def voice(self):
return "voice:" + self.noise

class dog(creature):
def __init__(self):
self.noise="bark"

then I get this outcome...
>>>import animal
>>> beagle=animal.dog
>>> beagle.voice()
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: unbound method voice() must be called with dog instance as
first argument (got nothing instead)
>>>

So I guess it wants something in position of self?

any idea what Im doing wrong? - this would be very handy as its a point
Im stymied on a couple of 'projects'
thanks
Glenn
> If you want dog.voice() to do something else, you can call superclass'
> method like this:
>
> def voice(self):
> creature.voice(self)
> print "brace your self"
> any_other_magic()
> 

> HTH
> -- 
> Roberto Bonvallet

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


Re: refering to base classes

2006-08-30 Thread glenn
>
> Shouldn't that be
>
> beagle = animal.dog()
>
> to create an instance?
>
> We've all done it ...
lol - actually Im confused about this - there seem to be cases where
instantiaing with:
instance=module.classname()
gives me an error, but
instance=module.classname
doesnt - so I got into that habit, except for where I had a constructor
with parameters - except now Im feeling foolish because I cant
replicate the error - which suggests I didnt understand the error
message properly in the first place... arrgh
I guess thats just part of the process of gaining a new language.

glenn

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


Re: refering to base classes

2006-08-30 Thread glenn
thanks - interesting essay/article -  a lot in their I've never really
considered - though its only recently ive started playing with multiple
inheritance in any context - thanks for that
Bruno Desthuilliers wrote:
> glenn wrote:
> > Bruno Desthuilliers wrote:
> >
> (snip)
> >>
> >> Here you could use a class attribute to provide a default:
> >>
> >> class Creature(object):
> >>   noise = ""
> >>
> >>   def voice(self):
> >> return "voice:" + self.noise
> >>
> >>
> >> class Dog(Creature):
> >>   noise="bark"
> >>
> >>   def voice(self):
> >> print "brace your self:"
> >> return Creature.voice(self)
> >> # can also use this instead, cf the Fine Manual
> >> return super(Dog, self).voice()
> >>
> (snip)
>
> > so for your $.02 do you see this as being, umm, superior in anyway to
> > creature.voice()?
>
> I suppose "this" refers to the use of super() ? If so, I wouldn't say
> it's "superior", but it can be helpful with complex inheritence scheme
> (something that does'nt happen very frequently in Python), and more
> specifically with multiple inheritance. You may want to read this for
> more infos:
>
> http://www.python.org/download/releases/2.2.3/descrintro/#mro
>
> HTH
> --
> bruno desthuilliers
> python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
> p in '[EMAIL PROTECTED]'.split('@')])"

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


analyzing removable media

2006-09-28 Thread glenn
Hi
can anyone tell me how given a directory or file path, I can
pythonically  tell if that item is on 'removable media', or sometype of
vfs, the label of the media (or volume) and perhaps any other details
about the media itself?
thanks
Glenn

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


Re: analyzing removable media

2006-09-28 Thread glenn
Hi  Jay
pls excuse top post - Im actually doing this project in linux, but am
wanting it to be cross platform. I definitley have to cater for win32
also.  I was hoping that burried in sys or os or that there'd be some x
platform  module that did all that stuff for me

thnks for reply though
glenn
Jay wrote:
> Well, in linux you can get a lot of info about where a file is based
> upon where it lies in the file system.  For example, if the folder the
> file is located in resides in the /media or /mnt directories, then the
> file is, barring a few rare circumstances, located upon a removable
> medium of some sort.  Once you get the name of that directory that is
> right below /media or /mnt, then you can cross check the name in
> /etc/fstab file.
>
> However, the contents of your post lead me to believe that you're
> working in a win32 environment.  That's a bit trickier.  Things aren't
> so simple.  You could probably grab similar information from the full
> path itself.  For example, just getting the drive letter that the file
> resides on could tell you a lot.  Now, where you'd cross check that is
> more of a mystery to me.  I'd guess the registry?  For an easier way of
> accessing the registry, I believe that the wrapper pywin32 may be of
> interest to you.  It shouldn't be that hard considering that you'd only
> be getting some information, not setting anything.
>
> If by chance we're talking about MacOS, I'm of almost no help.  In the
> case of MacOS X, it has a unix core, so I'd imagine that the method I
> described for linux could probably be adapted.
>
> Jay
>
> glenn wrote:
> > Hi
> > can anyone tell me how given a directory or file path, I can
> > pythonically  tell if that item is on 'removable media', or sometype of
> > vfs, the label of the media (or volume) and perhaps any other details
> > about the media itself?
> > thanks
> > Glenn

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


Re: analyzing removable media

2006-09-29 Thread glenn

>
>   As soon as you ask for "cross platform" and something that is
> device/OS specific... you have conflict.
>
> From the win32 extensions:
>
> win32file.GetDriveType
> int = GetDriveType()
>
> Determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk,
> or network drive.
>
> Return Value
> The result is one of the DRIVE_* constants.
>
>   I suspect Linux would require checking parameters in the fstab file.
Thanks for the tip Dennis

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


Re: analyzing removable media

2006-09-29 Thread glenn

Nick Vatamaniuc wrote:
> glenn wrote:
> > Hi
> > can anyone tell me how given a directory or file path, I can
> > pythonically  tell if that item is on 'removable media', or sometype of
> > vfs, the label of the media (or volume) and perhaps any other details
> > about the media itself?
> > thanks
> > Glenn
>
> It won't be trivial because one of the goals of the operating systems
> is to hide the differences between various types of storage devices and
> make them all look the same (i.e. a jump drive, a CD-ROM, a network
> volume are presented uniformly to the user as just another path in the
> file system).
>
> But you can probably use guesswork on unix OS's, as somebody above
> suggested, and examine the path. If the path contains common media
> mount points then that should give you a clue. On Windows you cannot
> easily know. For example if your file is on D:\file.txt, it is not
> immediatly obvious if D is a jumpdrive, a networked drive, a hard
> drive, or a CD-ROM.
>
> The only thing I can think of is to try to examine the Windows registry
> with the _winreg module. Here are the docs:
> http://docs.python.org/lib/module--winreg.html  There might be a key
> burried in there some place that will tell you which drives are what
> type.

ok - thanks - will look at that - Any one know what a Mac approach
might be? can I expect that playing anything I write with fstab or
`mount` will work on OSX?, or anyother BSD for that matter?

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


Re: English Idiom in Unix: Directory Recursively

2011-05-18 Thread Glenn Knickerbocker
On 05/18/2011 02:50 AM, Harrison Hill wrote:
> Recursion: (N). See recursion.

The index of IBM's Document Composition Facility SCRIPT/VS Text
Programmer's Guide, Release 3.0 (form SH35-0069-2), put it thus:

> Circular definition
> See definition, circular
> definition
> circular  211
> See also circular definition

Sadly, only the Release 4 manuals are available online anymore.

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


Re: print without ()

2017-09-06 Thread Glenn Hutchings
On Thursday, 7 September 2017 07:14:57 UTC+1, Andrej Viktorovich  wrote:
> Sometimes I find code with strange print function usage. String is passed 
> without brackets.
> 
> #!/usr/bin/python
> list = ['physics', 'chemistry', 1997, 2000];
> print "Value available at index 2 : "
> print list[2]
> list[2] = 2001;
> print "New value available at index 2 : "
> print list[2]
> 
> If I use command print "aaa" in console I get error. So, why this is allowed 
> in sample?
> 
> Sample from:
> https://www.tutorialspoint.com/python/python_lists.htm

That's because of a difference between python 2 and python 3.  In python 3, 
print is a function (which requires brackets).  In python 2 it was a keyword.  
The tutorial you're looking at is from python 2.
-- 
https://mail.python.org/mailman/listinfo/python-list


Reading the Windows Location API

2016-10-01 Thread Glenn Linderman
I found some GeoLocation stuff on PyPi, but it seems to be focused on 
turning an IP address into a (rough) location rather than reading a GPS. 
Seems like if a GPS is attached, reading it would be the best way to 
obtain a more accurate location, falling back to approximations if there 
is no GPS.


But I'm not sure where to start with reading the Windows Location API.  
Anyone have some clues or sample code?

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


Re: nltk related issue

2018-06-24 Thread Glenn Hutchings

On 21/06/18 04:40, Sharan Basappa wrote:
> Folks,
>
> I am trying to run a simple example associated with nltk.
> I get some error and I don't know what the issue is.
> I need some guidance please.
>

[...]

> LookupError:
> **
>Resource u'tokenizers/punkt/english.pickle' not found.  Please
>use the NLTK Downloader to obtain the resource:  >>>
>nltk.download()
>Searched in:
>  - 'D:\\Users\\sharanb/nltk_data'
>  - 'C:\\nltk_data'
>  - 'D:\\nltk_data'
>  - 'E:\\nltk_data'
>  - 
'D:\\Users\\sharanb\\AppData\\Local\\Enthought\\Canopy\\edm\\envs\\User\\nltk_data'
>  - 
'D:\\Users\\sharanb\\AppData\\Local\\Enthought\\Canopy\\edm\\envs\\User\\lib\\nltk_data'

>  - 'D:\\Users\\sharanb\\AppData\\Roaming\\nltk_data'
>  - u''
> **
>

As the error message says, you need to do a one-time installation of the 
NLTK data.  See http://www.nltk.org/data.html for more info.


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


Re: nltk related issue

2018-06-25 Thread Glenn Hutchings
  To: Sharan Basappa
From: Glenn Hutchings 

On 21/06/18 04:40, Sharan Basappa wrote:
 > Folks,
 >
 > I am trying to run a simple example associated with nltk.
 > I get some error and I don't know what the issue is.
 > I need some guidance please.
 >

[...]

 > LookupError:
 > **
 >Resource u'tokenizers/punkt/english.pickle' not found.  Please
 >use the NLTK Downloader to obtain the resource:  >>>
 >nltk.download()
 >Searched in:
 >  - 'D:\\Users\\sharanb/nltk_data'
 >  - 'C:\\nltk_data'
 >  - 'D:\\nltk_data'
 >  - 'E:\\nltk_data'
 >  -
'D:\\Users\\sharanb\\AppData\\Local\\Enthought\\Canopy\\edm\\envs\\User\\nltk_d
ata'
 >  -
'D:\\Users\\sharanb\\AppData\\Local\\Enthought\\Canopy\\edm\\envs\\User\\lib\\n
ltk_data'
 >  - 'D:\\Users\\sharanb\\AppData\\Roaming\\nltk_data'
 >  - u''
 > ******
 >

As the error message says, you need to do a one-time installation of the NLTK
data.  See http://www.nltk.org/data.html for more info.

Glenn

--- BBBS/Li6 v4.10 Toy-3
 * Origin: Prism bbs (1:261/38)
-- 
https://mail.python.org/mailman/listinfo/python-list


[ANNOUNCE] pysudoku 0.1

2005-07-08 Thread Glenn Hutchings
Announcing PySuDoku version 0.1, yet another Sudoku program written in
Python.  But this one has features that I don't see in any of the others:

  * Cute interactive solving mode via Tkinter.
  * Puzzle generation option, for making your own puzzles.
  * Nicely packaged for installation via distutils.

Sudoku, for the remaining 27 people in the world who don't know already, is
a logic puzzle where you have to fill in the numbers in a 9x9 grid so that
each row, column and 3x3 box has exactly one of the numbers 1-9 in them.

You can get pysudoku at:

http://www.freewebtown.com/zondo/programs

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


[ANN] PySuDoku version 0.2

2005-09-07 Thread Glenn Hutchings
Announcing PySuDoku version 0.2, yet another Sudoku program written in
Python, featuring:

  * Cute interactive solving mode via Tkinter.
  * Puzzle generation option, for making your own puzzles.
  * Nicely packaged for installation via distutils.

New in this release:

  * Now uses psyco module, if available, for speedups.

  * There's now a hints message indicating how the number was deduced,
courtesy of Paul Wayper <[EMAIL PROTECTED]>.

Sudoku, for the remaining 27 people in the world who don't know already, is
a logic puzzle where you have to fill in the numbers in a 9x9 grid so that
each row, column and 3x3 box has exactly one of the numbers 1-9 in them.

You can find PySuDoku at:

http://www.freewebtown.com/zondo/programs

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


Re: PyQt on MAC OS X

2004-12-13 Thread glenn andreas
In article <[EMAIL PROTECTED]>,
 Michael McGarry <[EMAIL PROTECTED]> wrote:

> One problem is my Window created in Qt appears underneath all others on 
> the screen and focus never goes completely onto this window. Kind of weird.
> 
> Any ideas?
> 

If the application is not properly bundled you will see symptoms like 
this - perhaps this is the problem?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pep8 in SetupTools

2013-12-12 Thread Glenn Hutchings
On Thursday, 12 December 2013 11:13:51 UTC, Chandru Rajendran  wrote:

> Please help me with running Pep8  using setuptools. Also help me how to Pep8 
> for files in a folder.

The tool you're looking for is flake8.  It integrates with setuptools, so that 
you can run 'python setup.py flake8'.  More information here:

http://flake8.readthedocs.org/en/2.0/setuptools.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using virtualenv to bypass sudoer issues

2014-02-08 Thread Glenn Hutchings

On 06/02/14 17:32, Jean-Michel Pichavant wrote:

> Assuming I have a debian workstation for which I don't have any sudo
> rights, in order to be able to install / remove python packages, should
> I be using virtualenv ? Is it a suited solution ?

It depends on whether you need to share the installation with anyone 
else.  If not, you could also install packages using:


python setup.py install --user

This will install in your home directory, in the '.local' subdirectory. 
 And to run any scripts that get installed, add ~/.local/bin to your PATH.


Glenn

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


msvcr100.dll missing ... error started after Windows 10 update to 10586.17

2015-12-04 Thread Glenn Linderman

My wife's 64-bit Win8 home machine has 32-bit Python 3.3 installed.

Then it upgraded to Win 8.1. Then I upgraded it to Win 10. Then I 
upgraded it to Threshold 2. It gets regular automatic updates also, like 
the one last night to build 10586.17.


That's the history.

When she tried a python script today, it failed, with an error saying 
that MSVCR100.dll was missing.


After a few false starts, like being surprised that the error happened 
when it worked yesterday, and that there was an MSVCR100.dll in 
%windir%\system32, doing a search for all MSVCR100.dll on her machine 
discovered quite a few in various application directories, but then also 
one in \windows.old\WINDOWS\SysWOW64, the light-bulb blinked on, I 
copied that one to the \python33 directory, and everything works.


Why M$ chose to delete MSVCR100.dll from %windir%\SysWOW64 in the recent 
update is a mystery, however.


So this is just a data point and warning and solution, not really an 
expectation that anyone will be able to explain M$.


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


Re: Unable to use python 3.5

2015-12-23 Thread Glenn Hutchings
On Wednesday, 23 December 2015 12:46:43 UTC, Ankit Deshmukh  wrote:
> I am maters student in India, I have installed python 3.5 in my windows 10
> 64bit machine. Everything works fine except package installing. When in use
> "pip install numpy" is shows unable to find *'vcvarsall.bat'* I don't know
> how to fix it. I tried several things nothing works.

You might find the following useful (I had the same problem):

http://stackoverflow.com/questions/2817869/error-unable-to-find-vcvarsall-bat
-- 
https://mail.python.org/mailman/listinfo/python-list


EOFError: marshal data too short -- causes?

2015-12-28 Thread Glenn Linderman

Here's a sanatized stack trace off my web server:

  File ".../cgihelpers.py", line 10, in
import cgitb
  File ".../py34/lib/python3.4/cgitb.py", line 24, in
import inspect
  File ".../py34/lib/python3.4/inspect.py", line 54, in
from dis import COMPILER_FLAG_NAMES as _flag_names
  File "", line 2237, in _find_and_load
  File "", line 2226, in _find_and_load_unlocked
  File "", line 1200, in _load_unlocked
  File "", line 1129, in _exec
  File "", line 1467, in exec_module
  File "", line 1570, in get_code
  File "", line 656, in _compile_bytecode
EOFError: marshal data too short


It worked this morning, and does this now.  I hadn't changed anything.

The only reference I find on Google seems to be related to 
out-of-disk-space, so I cleaned up some files, but I'm not sure of how 
the web server mounts things; df didn't show particularly high usage in 
any of the disks it reported on.


The files I cleaned up are ever-growing log files that I need to clean 
up now and then manually, but cleaning them up didn't help... and df 
wasn't complaining anyway. So maybe out-of-disk-space is a red herring, 
or only one cause of this symptom.


When I log in to the web server with Putty, I can run Python at the 
command prompt, and "import dis" suffices to reproduce the problem.


Are there other causes of this symptom than out-of-disk-space?  If it is 
out-of-disk-space, how could one determine which disk?


Maybe if not really out of space, it is a bad permission, disallowing 
creation of a temporary file?  But how could one determine which 
temporary file, and where it would be written?



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


Re: EOFError: marshal data too short -- causes?

2015-12-29 Thread Glenn Linderman

On 12/28/2015 11:19 PM, Terry Reedy wrote:

On 12/29/2015 1:50 AM, Glenn Linderman wrote:

Here's a sanatized stack trace off my web server:

   File ".../cgihelpers.py", line 10, in
 import cgitb
   File ".../py34/lib/python3.4/cgitb.py", line 24, in
 import inspect
   File ".../py34/lib/python3.4/inspect.py", line 54, in
 from dis import COMPILER_FLAG_NAMES as _flag_names
   File "", line 2237, in _find_and_load
   File "", line 2226, in _find_and_load_unlocked
   File "", line 1200, in _load_unlocked
   File "", line 1129, in _exec
   File "", line 1467, in exec_module
   File "", line 1570, in get_code
   File "", line 656, in _compile_bytecode
EOFError: marshal data too short


It worked this morning, and does this now.  I hadn't changed anything.


Since it crashes trying to unmarshal compiled dis bytecode, I would 
assume that the .pyc file is corrupted and remove it. Based on the 
above, it should be in

.../py34/lib/python3.4/__pycache__/dis.*.pyc
Python will then recompile dis and write a new .pyc file.



Thank you, thank you, thank you, thank you, thank you, thank you, thank 
you, thank you, thank you, thank you, thank you, thank you, thank you, 
thank you, thank you, thank you, thank you, thank you, thank you, thank 
you, thank you, thank you, thank you, thank you, thank you, thank you, 
thank you, thank you, thank you, thank you, thank you, thank you, thank 
you, thank you, thank you, thank you, thank you, thank you, thank you, 
thank you!


The site is working now, again.  Thank you, again.

Because of the File "" lines, and the fact that there were recent 
comments about frozen import stuff on python-dev, I was thinking that 
the corruption was at a lower level, and never thought to zap a .pyc.


OK, so I actually renamed it instead of zapping it.  Them, actually, 
there were both .pyc and .pyo.


Now the __pycache__ directory is full of .pyc and .pyo files (from the 
install? On April 19th? (the date on most of the files).  But:


[email protected] [~/py34/lib/python3.4/__pycache__]# ll dis*
-rw-r--r-- 1 areliabl areliabl 14588 Dec 29 00:27 dis.cpython-34.pyc
-rw-r--r-- 1 areliabl areliabl  8192 Dec 28 19:16 dis.cpython-34.pyc-xxx
-rw-r--r-- 1 areliabl areliabl 14588 Apr 19  2015 dis.cpython-34.pyo-xxx

(I renamed the existing .py* files by appending -xxx).

So we can see that somehow, today at 19:16 (probably UTC) the dis.*.pyc 
file got chopped to 8192 bytes. That's a suspicious number, being a 
power of 2... but... I haven't updated Python since originally 
installing it on the web server, on April 19th.  So why would _that_ 
.pyc file have today's date? Because of UTC, the replacement has 
tomorrow's date :)  But it seems like it should have had Apr 19 2015 
like all the rest.


Except, all the rest don't have Apr 19 2015... most of them do, but 
there are a fair number from today, and a couple from Dec 15 (listed 
below).  I don't quickly see any others that are suspiciously exactly a 
power of 2!


But, under the assumption that the install created all these files in 
the first place, why would _any_ of them have newer dates?  I haven't 
gone around deleting any .pyc files since April.  And if they are 
already there, why would Python rebuild them? Isn't the point of the 
.pyc files to not need to recompile?  And even if the original build 
didn't build them, since I haven't touch the python sources on this web 
server for months, shouldn't all the files be months old, at least?


And isn't it rather suspicious that of the ones that are rebuilt, that 
all of them have exactly the same timestamp, rather than being sprinkled 
around with different dates?  Well, the two from Dec 15 have the same 
time, and all the ones from today have the same time. But that doesn't 
seem like some sort of "random error or access conflict accessing file 
causing it to be rebuilt"


Should I accuse my web host of playing with these files?  Are they 
backing up/restoring?  Are they simply touching the files? Is their 
infrastructure flaky such that whole groups of files get deleted now and 
then (and either rebuilt or restored with a different date)?



[email protected] [~/py34/lib/python3.4/__pycache__]# find 
-mtime -240 -ls

113654924   20 drwxr-xr-x   2 areliabl areliabl20480 Dec 29 00:27 .
113639463   76 -rw-r--r--   1 areliabl areliabl76650 Dec 28 19:16 
./inspect.cpython-34.pyc
113639477   16 -rw-r--r--   1 areliabl areliabl14588 Dec 29 00:27 
./dis.cpython-34.pyc
113639458   16 -rw-r--r--   1 areliabl areliabl12361 Dec 28 19:16 
./ast.cpython-34.pyc
113639451   36 -rw-r--r--   1 areliabl areliabl32773 Dec 28 19:16 
./shutil.cpython-34.pyc
113639468   12 -rw-r--r--   1 areliabl areliabl10371 Dec 28 19:16 
./contextlib.cpython-34.pyc
113639469 

Re: EOFError: marshal data too short -- causes?

2015-12-30 Thread Glenn Linderman

On 12/29/2015 5:56 AM, D'Arcy J.M. Cain wrote:

On Tue, 29 Dec 2015 00:01:00 -0800
Glenn Linderman  wrote:

OK, so I actually renamed it instead of zapping it.  Them, actually,

Really, just zap them.  They are object code.  Even if you zap a
perfectly good .pyc file a perfectly good one will be re-created as
soon as you import it.  No need to clutter up you file system.

Yes, the only value would be if the type of corruption could be 
determined from the content.

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


Re: EOFError: marshal data too short -- causes?

2015-12-30 Thread Glenn Linderman

On 12/29/2015 1:00 PM, Terry Reedy wrote:
I updated to 2.7.11, 3.4.4, and 3.5.1 a couple of weeks ago, so the 
timestamps are all fresh.  So I don't know what happened with 3.4.3 
timestamps from last April and whether Windows itself touches the 
files.  I just tried importing a few and Python did not. 


I'm a Windows user, too, generally, but the web host runs Linux.

I suppose, since the install does the compileall, that I could set all 
the __pycache__ files to read-only, even for "owner".  Like you said, 
those files _can't_ be updated without Admin/root permission when it is 
a root install... so there would be no need, once compileall has been 
done, for the files to be updated until patches would be applied.  This 
isn't a root install, though, but a "user" install.


Level1 support at the web host claims they never touch user files unless 
the user calls and asks them to help with something that requires it. 
And maybe Level1 support religiously follows that policy, but other 
files have changed, so that policy doesn't appear to be universally 
applied for all personnel there... so the answer isn't really responsive 
to the question, but the tech I talked to was as much a parrot as a tech...


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


Re: EOFError: marshal data too short -- causes?

2016-01-08 Thread Glenn Linderman

On 1/7/2016 7:44 PM, Dennis Lee Bieber wrote:

On Thu, 7 Jan 2016 10:55:38 -0800, Glenn Linderman 
declaimed the following:


But all the touched files are .pyc files (and the directories
__pycache__ directories).  None of the source files were modified. So
why would any .pyc files ever be updated if the source files are not?
Are there _any_  Python-specific reasons?


Two different versions of Python accessing the same modules? That might
induce one to do a rebuild of the .pyc from the .py... Especially if the
variant is something being run (directly or indirectly) from some scheduled
task.


Thanks for the idea, but there is only one version of Python installed 
in that directory structure (and all of my "shared host" portion of the 
server).



Some conflict with a backup process corrupting files?


This seems more possible, simply because I don't understand their backup 
process. Still, if Python only reads shared, and there'd be no reason 
for a backup process to do more than read shared, there shouldn't be a 
conflict...


But it seems clear that there _is_ some conflict or some mysterious bug 
that is triggering something.


The installation happened really fast, when I did it, many many files 
seem to have the same timestamp. Maybe some of the sources are really 
close in touch time to the .pyc? But still, it seems that would have 
been resolved long ago...  But I could go "touch" all the .pyc to give 
them nice new timestamps?


Maybe I should mark all the current .pyc  read-only even to myself? That 
would prevent them from being rebuilt by Python, and maybe when whatever 
goes wrong goes wrong, an error would return to the user, but maybe the 
next access would work that'd be better than letting whatever goes 
wrong modify/corrupt the .pyc, so that _every future_ access fails?


Maybe before launching Python I should do a "find ~/py34 --name *.pyc > 
/dev/null" (or some log file) to cache the directory structure before 
Python looks at it, and give the mysterious bug a chance to happen with 
an irrelevant activity?


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


Some Help getting started

2015-10-12 Thread Glenn Schultz
Hello All,

I have an application written in R for the analysis of mortgage-backed and 
asset-backed securities.  I am in the process of writing it in Python.  I need 
some help getting started.Here is the repository

https://github.com/glennmschultz/Bond_Lab

I think I have the deployment setup properly but I can't seem to install the 
deployment.  I tried
pip install - e . but that did not work.  I have been reading all day and have 
made very little progress.  I expect its simple but so far I have not found the 
magic bullet.  

The R version was used to write a book which is coming out in Feb so the Python 
version will benefit from earlier mistakes.

http://www.amazon.com/Investing-Mortgage-Backed-Securities-Website/dp/1118944003/ref=sr_1_1?ie=UTF8&qid=1444689641&sr=8-1&keywords=glenn+schultz

I have two Python books I have been reading but at some point one just has to 
get to it.  Any advise as to what I am doing wrong is greatly appreciated

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


New to Python and setting up

2015-10-17 Thread Glenn Schultz
Hello All,

I am setting a Python deployment which is a refactor of an R package which I 
programmed (BondLab). Below is the github link to the python bond lab

https://github.com/glennmschultz/Bond_Lab

Following the example of Ivan I have setup A folder structure.  My 
understand is that if each folder has an __init__.py  From what it is 
considered a module.  Have I set this up correctly?

In the time_value module I have a function present_value_factor.   I am having 
trouble documenting the function.  How is this done?  

Finally, I have read something to the effect that when creating a deployment 
locally use a virtual environment but I am not sure what that means in this 
case.  What is the workflow here?  I am having a hard time finding good primers 
on the subject.

I would like to get Bond Lab python up to speed before I open BondLab R.  
Basically, the idea is to let them shoot it out (Bond Lab Py and BondLab R) for 
supremacy.

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


Launcher, and ftype Python.File

2015-11-18 Thread Glenn Linderman
Setting up a new machine with Windows 10, I installed Python 3.5.0 and 
the Launcher. Invoking python files from batch files as


foo.py -a -bunch -of -parameters

Didn't seem to do _anything_ so I checked:

d:\>assoc .py
.py=Python.File

d:\>ftype Python.File
Python.File="C:\Windows\py.exe" "%L" %*

I'm surprised by the "%L" where usually programs have "%1". Is this a 
new Windows feature I don't know about yet, or is it a bug in the 
installer for the Launcher?


ftype /?  does not enlighten me that there is a new %L feature available.


I did upgrade to Threshold 2 after installing Python and before using 
it, if that matters, just due to the timing of setting up the new machine.


Turns out I had an empty file named foo.py and that is why it didn't do 
anything, but now I'm just really puzzled about what "%L" means... 
Google doesn't support searching for "%L" very well.

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


Re: Exploring Python for next desktop GUI Project

2014-07-24 Thread Glenn Linderman

On 7/24/2014 11:15 AM, Chris Angelico wrote:

On Fri, Jul 25, 2014 at 4:04 AM, Mark Lawrence  wrote:

On 24/07/2014 17:18, Chris Angelico wrote:

The first one is certainly possible. Pick any of the well-known
toolkits (Tkinter, wxwidgets, GTK, etc), and see how it feels. All of
them are portable across the three platforms you name, so see which
one is most comfortable for you to code in and produces the best
results.


s/wxwidgets/wxpython/ unless you fancy wrapping it yourself :)


Yeah that. And pygtk rather than GTK. Or I could have gone the other
way and said Tk instead of Tkinter. One way or another, I ought to
have been more consistent. Anyway. Pick a good toolkit, get to know
it, and use it. Personally, I like GTK, but that's partly because its
bindings come with Pike, and I did GUI work with Pike before I did
with Python; the same advantage, for someone starting with Python,
goes to Tk. But the main thing is, it's easy to be cross-platform -
take whatever feels good to you.

ChrisA
Not knowing any of these GUI platforms (although I've read some about 
Tk), I have some questions.


* Which of them use UTF-8 as their native Unicode interface?

* Which makes it easiest to discover and adjust font metrics such as 
kerning?


* Which makes it easiest to obtain bounding rectangles of a piece of text?

* Which makes it easiest to use a set of fonts such as Times (for Latin) 
and others for Cyrillic, Chinese, and Korean? Or which supplies a font 
configuration that can "just be used" for any language?


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


Re: Python 3 is killing Python

2014-08-01 Thread Glenn Linderman

On 7/16/2014 7:27 AM, Frank Millman wrote:

I just tried an experiment in my own project. Ned Batchelder, in his
Pragmatic Unicode presentation, http://nedbatchelder.com/text/unipain.html,
suggests that you always have some unicode characters in your data, just to
ensure that they are handled correctly. He has a tongue-in-cheek example
which spells the word PYTHON using various exotic unicode characters. I used
this to populate a field in my database, to see if it would display in my
browser-based client.

The hardest part was getting it in. There are 6 characters, but utf-8
requires 16 bytes to store it -

 
b'\xe2\x84\x99\xc6\xb4\xe2\x98\x82\xe2\x84\x8c\xc3\xb8\xe1\xbc\xa4'.decode('utf-8')

However, that was it. Without any changes to my program, it read it from the
database and displayed it on the screen. IE8 could only display 2 out of the
6 characters correctly, and Chrome could display 5 out of 6, but that is a
separate issue. Python3 handled it perfectly.


wrapping the above in a print(), on Windows, I get:

Traceback (most recent call last):
  File "D:\my\py\python-utf8.py", line 1, in 
print(b'\xe2\x84\x99\xc6\xb4\xe2\x98\x82\xe2\x84\x8c\xc3\xb8\xe1\xbc\xa4'.decode('utf-8'))
  File "C:\Python33\lib\encodings\cp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 
0-5: character maps to 


So Python3 doesn't handle it perfectly on Windows.  And I saw someone 
blame the Windows console for that... but the Windows console can 
properly display all those characters if the proper APIs are used. The 
bug is 7 years old: http://bugs.python.org/issue1602 and hasn't been 
fixed, although the technology for fixing it is available, and various 
workarounds (with limitations) have been available for 5 years, and 
patches have been available for 3 years that work pretty good. However, 
just a few days ago, 26 July 2014, Drekin had an insight that may 
possibly lead to a patch that will work well enough to be integrated 
into some future version of Python... I hope he follows up on it. This 
is a serious limitation, and it is, and always has been, a bug in Python 
3 Unicode handling on Windows.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-03 Thread Glenn Linderman

On 8/3/2014 4:25 PM, Andrew Berg wrote:

On 2014.08.03 18:08, Chris Angelico wrote:

The best way to do it is to use the Unicode codepage, but cmd.exe just
plain has issues. There are underlying Windows APIs for displaying
text that have problems with astral characters (I think that's what it
is), so ultimately, you're largely stuck.

That is not quite true. The terminal has these issues, not the shell. Using
cp65001 does make Unicode in a Windows terminal possible, but using a better
terminal[1] makes it almost perfect (my experience has been that input can be
difficult, but output works well). I personally have used an IRC bot written in
Python with logging output containing Unicode characters that display just fine
(both locally and over SSH).

[1] I recommend ConEmu: https://code.google.com/p/conemu-maximus5/

I will be reading more about conemu, thanks for the reference.

http://bugs.python.org/issue1602  describes 7 years worth of discussion 
of the problems with the console/terminal used by default by cmd.exe and 
other Windows command line programs, versus Python.


The recent insights in the last couple weeks have given me hope that 
Python might be able to be fixed to work properly with the default 
Windows console at long last... at least for non-astral characters (I'm 
not sure whether or not the Windows console supports non-BMP characters).


For this OP problem, it is mostly a matter of finding a fixed-width font 
that supports the box drawing characters and the Polish characters that 
are desired.  Lucida Console has a fair repertoire, and Consolas has a 
fair repertoire, in the fixed-width font arena. There may be others, 
documented on Polish language web sites that I wouldn't know about, and 
I don't know enough Polish to be sure those I mentioned suffice.


And then, the workarounds mentioned in the above-referenced bug or on 
the GitHub or PyPi sites mentioned should provide any needed additional 
solutions... and hopefully something along this line finally integrated 
into Python so that it can finally be said that Python supports Unicode 
properly on Windows (or at least as properly as Windows allows... but it 
is pretty clear that Windows supports Unicode, even for the console, 
using different APIs that Python is presently using, and that mismatch 
between APIs is really the source of the problems with using Unicode in 
Python on Windows).


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


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-03 Thread Glenn Linderman

On 8/3/2014 5:17 PM, Glenn Linderman wrote:

On 8/3/2014 4:25 PM, Andrew Berg wrote:

On 2014.08.03 18:08, Chris Angelico wrote:

The best way to do it is to use the Unicode codepage, but cmd.exe just
plain has issues. There are underlying Windows APIs for displaying
text that have problems with astral characters (I think that's what it
is), so ultimately, you're largely stuck.

That is not quite true. The terminal has these issues, not the shell. Using
cp65001 does make Unicode in a Windows terminal possible, but using a better
terminal[1] makes it almost perfect (my experience has been that input can be
difficult, but output works well). I personally have used an IRC bot written in
Python with logging output containing Unicode characters that display just fine
(both locally and over SSH).

[1] I recommend ConEmu:https://code.google.com/p/conemu-maximus5/

I will be reading more about conemu, thanks for the reference.


Having read a bit about ConEmu, it seems that it is a "pretty face" 
built on top of Windows Console, by screen scraping the real (but 
hidden) Windows Console, and providing a number of interesting display 
features and modes. So while it adds functionality to the Windows 
Console interface, it doesn't seem like it is likely to fix bugs or 
resolve issues with code pages, font selection, or Unicode character 
repertoires, which are the issues of this thread and the bug I 
referenced earlier.


Can anyone with ConEmu installed refute this interpretation of its 
functionality?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Glenn Linderman

On 8/3/2014 10:06 PM, Andrew Berg wrote:

On 2014.08.03 23:14, Glenn Linderman wrote:

Having read a bit about ConEmu, it seems that it is a "pretty face" built on
top of Windows Console, by screen scraping the real (but hidden) Windows
Console, and providing a number of interesting display features and modes. So
while it adds functionality to the Windows Console interface, it doesn't seem
like it is likely to fix bugs or resolve issues with code pages, font
selection, or Unicode character repertoires, which are the issues of this
thread and the bug I referenced earlier.

Can anyone with ConEmu installed refute this interpretation of its 
functionality?


If you run cmd in it, you will still need to use cp65001.
Or some workaround. The latest workaround in the issue I referenced does 
not require cp65001 either, for output, at least.



This is not necessary
for  (or applicable to) other applications (such as a Python interpreter) run
directly.
How does one "directly run" another application using ConEmu? That 
wasn't clear from what I found to read. It sounded like you run ConEmu, 
run one or more shells within it, and launch programs from those shells? 
And so it was also unclear if a program launched from some batch file 
would have to have the batch file launched from ConEmu, also. Or does 
ConEmu grab the execution association for batch files to make that work 
more automatically?



ConEmu can use any arbitrary font available on the system. As I have
said, I have been able to display Unicode output on it from an application
written in Python. No mojibake, no replacement characters, just the exact
characters one would expect.
I do not know the internals of ConEmu and how it interacts with conhost and
whatever else, but I have not found a need to since it has just worked for me.
So you may not know the internals of ConEmu, but I presume you know the 
internals of your Python applications. What encodings do you use for 
stdout for those applications? Do you set up the Python environment 
variables that specify some particular encoding, in the ConEmu 
environment (or does it)? Because the default Python IO encoding in 
Windows seems to be obtained from the configured code page.


Of course the biggest problem with much free and open source software is 
the documentation; I wasn't able to find specific answers to all my 
questions by reading the ConEmu wiki. Maybe some of it would be clearer 
if I installed it, and your "just worked" comment is certainly 
encouraging me to "just try it", but while trying it may help me figure 
it out, adding another package to separately install for my users gives 
more complexity. See if you can push me over the edge :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Glenn Linderman

On 8/4/2014 1:39 AM, Terry Reedy wrote:

On 8/3/2014 6:52 PM, Wiktor wrote:


Hi,

as OO programming exercise, I'm trying to port to Python one of my 
favorite

game from early'90 (Atari 65XL/XE) - Kolony (here's video from original
version on C64 https://www.youtube.com/watch?v=UFycYOp2cbE, and here's


This appears to be an actual text screen, no graphics.


video from modern rewritten (for Atari emulators) version: Kolony 2106
https://www.youtube.com/watch?v=eX20Qqqm5eg - you get the idea? ;-)).


This appears to be text boxes on a graphics screen.

OO Design is one thing, but I want to make it look as near as 
possible to

the original (those windows-like menus in console window).


Which original? the C64 or Atari.  The important characteristic of 
both is that both have multiple overlapping popup boxes. This means 
that either you or a widget framework much keep track of stacking 
order and how to restore what was hidden when a box goes away or is 
moved down in the stacking order. I would not be surprised if the 
Atari had at least a rudimentary widget framework.


> I tried to use
'standard' Unicode characters (I can see that most of my Windows 
monospaced

fonts have them) to draw frame around menu. Something like this:

  ┌──╖
  │ Construction ║
  │ Production   ║
  │ Research ║
  │ Exploration  ║
  ├··╢
  │ Next turn║
  ╘══╝

(I like the look of double lines on right and at the bottom)
But when I try to print those characters, I get an error:

| Traceback (most recent call last):
|   File "E:\Moje dokumenty\python\kolony\menu.py", line 14, in 
| """
|   File "C:\Python34\lib\encodings\cp852.py", line 19, in encode
| return codecs.charmap_encode(input,self.errors,encoding_map)[0]
| UnicodeEncodeError: 'charmap' codec can't encode character '\u2556' 
in position 1

| 6: character maps to 


You have two separate problems with running in the windows console.

1. The character issue. If you run a program to just print the above 
from an Idle editor, so that the output is printed to the Idle shell, 
there should be no problem.

>>> print('\u2556'*10)
╖╖
But characters are not your real issue.

2. The random access issue. The MS console in normal use is like a 
serial printer or terminal. Once a line is printed, it cannot be 
changed. I looked at the video and the program randomly accesses a 24 
or 25 line x 80 column screen, overprinting existing characters at 
will and reversing black on white versus white of black at will.  
MSDOS screens recognized standard ANSI screen control codes once the 
ANSI.SYS driver was installed, which was fairly normal. But cmd.exe is 
actually a regression from MS-DOS in that it apparently will not allow 
this.  Or it is a hugh pain.


You could get a program that emulates a full-screen ANSI terminal, and 
learn to use ANSI control codes.  Or you could use a tkinter (tk) Text 
widget. People have written at least serial terminal emulators for 
Text, but I did not find a full-screen.


Using tkinter, I would try making each box a separate text box placed 
in a frameand let tkinter worry about displaying them correctly and 
detecting which box get a mouse click or  key.


I've never used the API from Python but random console access is 
documented at 
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687404%28v=vs.85%29.aspx
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Glenn Linderman

On 8/4/2014 3:33 AM, Andrew Berg wrote:

If you want to save your users the hassle, I would definitely
recommend a graphical environment. If I had realized that you intended your
application to be widely deployed, I would have simply recommended that from
the start.


Graphical environments are good for some things, command line 
environments are good for other things.


Unicode capability is beneficial in both.

Many of the software tools I create and distribute are command line 
utilities, for people that use command lines anyway.  The problems arise 
when they are multilingual, and need to use diverse character repertoires.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cmd.exe on WIndows - problem with displaying some Unicode characters

2014-08-04 Thread Glenn Linderman

On 8/4/2014 3:24 AM, Wolfgang Maier wrote:

On 08/04/2014 11:53 AM, Glenn Linderman wrote:


I've never used the API from Python but random console access is
documented at
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687404%28v=vs.85%29.aspx 





Would using the API from Python involve doing the wrapping yourself or 
do you know about an existing package for the job ?


I haven't used the API from Python. I haven't checked PyWin32 to see if 
it already wraps that API like it wraps so many other APIs. I haven't 
Googled using "python" and "WriteConsoleOutput" to see if other packages 
may exist to do the job. But these are the things that I would do if I 
had a need to write a program like yours, since I know that the console 
does, in fact, support random access.




By the way (and off-topic), how would you do it on Linux?


Off topic? It is still about doing it using Python, no?

I believe that most Unix terminal emulators, which are used for running 
shells and command lines, support cursor controls, and I believe most of 
them have a mode that emulates the DEC VT-52 terminal, one of which I 
had physical access to at the "computer lab" at the university I 
attended so many years ago. The VT-52 defined escape sequences to move 
the cursor around on the screen, providing random access. Text-based, 
screen-oriented programs such as emacs leveraged such capabilities quite 
effectively.


There may be something better today, I haven't used Unix for a dozen 
years now, and the usage at that time was database development not 
text-based graphics. I've used Linux only on my web host, and a little 
experimentation on a local machine I installed it on here, until the 
machine died, and I didn't do any text-based graphics in either of those 
circumstances either.  So probably college was the last time I used 
text-based graphics, but that was using RSTS and DECsystem 20 (forget 
the name of the OS for that machine) on VT-52 terminals. But I've noted 
with amusement that the VT-52 (and later enhanced models) are still 
supported by Unix/Linux terminal emulators and X system.


Unix abstracts that cursor motion using "curses" and I believe there are 
curses implementations for Windows as well, but I've not attempted to 
use curses from Python on either Unix or Windows.





Wolfgang



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


Re: Python code in presentations

2014-10-01 Thread Glenn Hutchings
On Tuesday, 30 September 2014 12:51:00 UTC+1, Jean-Michel Pichavant  wrote:
> I'm currently writing a presentation to help my co-workers ramp up on new 
> features of our tool (written in python (2.7)).
> 
> I have some difficulties presenting code in an efficient way (with some basic 
> syntax highlights). I need to be catchy about the code I'm presenting 
> otherwise the presentation will fail and I would be better saying to my 
> co-workers "RTFM", cause there is a manual.

A good option is to use reStructuredText and the rst2s5 converter 
(http://docutils.sourceforge.net/docs/user/slide-shows.html).  It can do syntax 
highlighting of python, and produces a slide show you display in a browser.  An 
example of what you can produce is at http://farmdev.com/talks/unicode.

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


Re: Code Review for Paper, Rock, Scissors

2014-10-14 Thread Glenn Hutchings
Hi there!   Welcome to Python.

On Tuesday, 14 October 2014 09:04:51 UTC+1, Revenant  wrote:
> I am new to Python and would also like to see if any of you programming
> gurus have some suggestions about how I can simplify code, and also if
> there are any other good starter programs to work on to improve my
> skills.

I'm sure you'll get a lot of helpful advice here.  Here's a start: you have
a lot of places where you're comparing variables to the capitalized and
lower-case versions of the same string.  You could halve that number if you
converted your input to lowercase first.  For example:

if menuselection == 'play' or menuselection == 'Play':

changes to:

if menuselection.lower() == 'play':

There are plenty of other string methods you might find useful.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python install on locked down windows box?

2011-09-22 Thread Glenn Hutchings
You could try Portable Python (http://www.portablepython.com).  No need to 
install anything!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python tools for managing static websites?

2006-11-02 Thread Glenn Hutchings
I haven't seen mention of HTMLgen, another python package.  Check it
out at:

http://starship.python.net/crew/friedrich/HTMLgen/html/main.html

Glenn

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


Re: setup.py and file extensions like ".c++"

2006-08-24 Thread Glenn Hutchings
[EMAIL PROTECTED] wrote:
> Is there any way to get setup.py to recognize file extensions like .c++
> in lieu of .cpp?  I'd love to not have to rename the source files for
> the library I'm trying to wrap in a python C extension.

The python docs imply that the file extension is dealt with by the
native C++ build system, so you have to use a recognized suffix (either
.cpp or .cc, and possibly others).  Looks like .c++ isn't a standard
one.  See

http://docs.python.org/dist/describing-extensions.html#SECTION00232

Glenn

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


Re: tuple.index()

2006-12-14 Thread Glenn Hutchings
Nick Maclaren wrote:
> Why doesn't the tuple type have an index method?  It seems such a
> bizarre restriction that there must be some reason for it.

In fact, tuples have no non-__underscored__ methods at all.  The list
count() method would also be useful for tuples, since it doesn't modify
anything.  I have no idea why they aren't implemented either.

Glenn

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


Re: tuple.index()

2006-12-14 Thread Glenn Hutchings
Simon Brunning wrote:
> It's because, philosophically, a Python tuple isn't just a read-only list.

But there are situations where you might want to treat it as a
read-only list.  E.g., an argument to a function, so that you can
guarantee the function won't modify it.  In that case, it makes sense
for the non-modifying methods (index() and count()) to be available.

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


Re: tuple.index()

2006-12-14 Thread Glenn Hutchings
Roberto Bonvallet wrote:
> list(my_arg).index(...)

Absolutely -- you can work around the limitation without any problems.
But the question is, why doesn't the list type share all its
non-modifying methods with the tuple type?  All the previous arguments
about "homogenous" and "heterogenous" in this thread sound bogus to me.
Python is first and foremost a practical language; what lists and
tuples are supposedly "for" strikes me as being irrelevant.

Glenn

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


Re: tuple.index()

2006-12-14 Thread Glenn Hutchings
Fredrik Lundh wrote:
> if you cannot trust your own code not to modify objects you pass to it,
> I'm not sure Python's the right language for you.

It's not my own code I'm worried about. :-)

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


Re: tuple.index()

2006-12-14 Thread Glenn Hutchings
Fredrik Lundh wrote:
> if you don't want to understand the design, nobody can force you.  but arguing
> that the people behind the design "don't get it" isn't very practical.

I'm not arguing that at all.  What I'm saying is that from the
perspective of someone not interested in design issues, it seems like
an omission for tuples to be missing the non-modifying methods that
lists have.

Glenn

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


Re: tuple.index()

2006-12-14 Thread Glenn Hutchings
Nick Maclaren wrote:
> I remain baffled.  I accept the explanations, but what I am now
> confused by is the reason for the explanations 

Maybe this archive posting, straight from the horse's mouth, will clear
things up once and for all...

http://www.python.org/search/hypermail/python-1992/0285.html

Glenn

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


Wrapping c functions

2005-05-01 Thread Glenn Pierce
Hi I have been trying to wrap a c library called FreeImage for python 
and am having trouble with a couple of functions.

One function is
FreeImage_Load which takes parameters (enum, const char*, int)
I have wrapped the function with the following code
static PyObject *
freeimage_load(PyObject *self, PyObject *args)
{
   int format, flags;
   char* filename = "None";
   FIBITMAP *dib = NULL;
   if (!PyArg_ParseTuple(args, "isi", &format, filename, &flags))
   return NULL;
   dib = FreeImage_Load(format, filename, flags);
   return Py_BuildValue("o", dib);
}
However I am getting a segmentation fault at PyArg_ParseTuple.
Also I have little Idea what to return from the function. FIBITMAP * is 
an opaque pointer
that I pass to other FreeImage functions, I pretty certain
Py_BuildValue("o", dib) is wrong.

There is also the function
unsigned char  *FreeImage_GetBits(FIBITMAP *dib);
I and not sure how to return the bits to python.
I would probably like to display an image with the gtk function
drawable.draw_rgb_image(*gc*, *x*, *y*, *width*, *height*, *dith*, *rgb_buf*, 
*rowstride*)
here the RGB Image data is packed in a string as a
sequence of 8-bit RGB pixel triplets
but I have no idea how to get from unsigned char  * to that.
Any advice would be greatly appreciated.
Thanks
--
http://mail.python.org/mailman/listinfo/python-list


libraries with distutils

2005-05-11 Thread Glenn Pierce
Hi I have a question about writing a portable setup.py script for distutils.

I have a directory structure like this.

FreeImage/
  |--Source/
  ||-- FreeImage.h
  |
  |--Dist/
  ||--FreeImage.lib
  ||--FreeImage.dll
  |
  |--Wrapper/
   |-Python/
   |--build/
   |
   
|--freeimagemodule.c
   |--setup.py



I want to create a setup file that works on both unix and Windows but I 
am having trouble with windows.
My setup.py file is like the following:

from distutils.core import setup, Extension

ext_module = Extension('freeimagewrapper',
define_macros = [('MAJOR_VERSION', '3'),
 ('MINOR_VERSION', '7')],
include_dirs = ['../../Source/'],
library_dirs=['../../Dist/'],
libraries = ['FreeImage'], 
sources = ['freeimagemodule.c'])

setup (name = 'freeimage',
   version = '1.0',
   author = 'Glenn Pierce',
   description = 'Python wrapper for the freeimage library',
   ext_modules = [ext_module])


I am getting link errors as vs can't seem to find ../../Dist/FreeImage.lib

The output is

running build
running build_ext
building 'freeimagewrapper' extension
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\link.exe /DLL 
/nologo
 /INCREMENTAL:NO /LIBPATH:../../Dist/ "/LIBPATH:C:\Program 
Files\Python24\libs"
"/LIBPATH:C:\Program Files\Python24\PCBuild" FreeImage.lib 
/EXPORT:initfreeimage
wrapper build\temp.win32-2.4\Release\freeimagemodule.obj 
/OUT:build\lib.win32-2.
4\freeimagewrapper.pyd 
/IMPLIB:build\temp.win32-2.4\Release\freeimagewrapper.lib

The errors are like

 Creating library build\temp.win32-2.4\Release\freeimagewrapper.lib and 
object
build\temp.win32-2.4\Release\freeimagewrapper.exp
freeimagemodule.obj : error LNK2019: unresolved external symbol 
_FreeImage_Unloa
d referenced in function _destroy

Also I guess when the python module is installed it will still need to 
find FreeImage.dll in a libray path searched by the system or will 
distutils place the actual dll and lib files where thay can be found ?

I have read the distutils guide but wasn't clear on the library section 
for ext modules.

Thanks for any help.

Glenn

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


Re: Tkinter - resize tkMessageBox

2007-06-05 Thread Glenn Hutchings
On 4 Jun, 21:29, [EMAIL PROTECTED] wrote:
> Is there a way to resize the width of the "tkMessageBox.askyesno"
> dialog box, so that the text does not wrap to the next line.

You can use the Tk option database, either explicitly or from a file.
For example, to set the wrap length of all dialogs to 10 inches, try
this:

   root = Tk()
   root.option_add("*Dialog.msg.wrapLength", "10i")

Regards,

Glenn

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


Re: Need a Little Help on Tkinter and Python

2007-06-06 Thread Glenn Hutchings
On 6 Jun, 00:58, "W. Watson" <[EMAIL PROTECTED]> wrote:
> is there a Tkinter intro manual somewhere

Take a look at http://www.pythonware.com/library/tkinter/introduction

Glenn

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


Re: using tkinter to display html

2007-04-19 Thread Glenn Hutchings
On 20 Apr, 02:54, "Stephen M. Gava" <[EMAIL PROTECTED]>
wrote:
> yeah. i feel like i'm being forced to use wxwidgets/wxpython just because
> i need pretty good html display though.

You could always use a real web browser:

import webbrowser
webbrowser.open_new("index.html")

Glenn

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


Re: Tkinter or wxpython?

2007-08-02 Thread Glenn Hutchings
On Aug 3, 1:00 am, "wang frank" <[EMAIL PROTECTED]> wrote:
> I want to build a GUI to execut python script. I found TKinter and
> wxpython. Which one is easier for a newbie? and which one is better?

Well, Tkinter comes with Python, so newbies can get up and running
straight away without having to download and install anything else.
And there are probably lots more examples out there that a newbie can
look at and learn from.  As for *better*, wxPython has a lot more
kinds of widgets in it, which will make writing GUIs less tedious in
the long run, and the widgets look a lot nicer too.

Glenn

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


Re: wxPython - drawing without paint event

2007-08-10 Thread glenn . chappell
On Aug 10, 1:40 am, 7stud <[EMAIL PROTECTED]> wrote:
> On Aug 9, 7:46 pm, Matt Bitten <[EMAIL PROTECTED]> wrote:
>
> > I've got a wxPython program that needs to do some drawing on a DC on a
> > regular basis And there is no event,
> > so my code doesn't get called. What do I do?
>
> Then the event is: "on a regular basis", i.e. the passage of time.
> You can use a wx.Timer to create events at regular intervals, which
> your code can respond to:
> ...

Thanks!

On a related topic, it seems like it would be nice to do *all* drawing
in
response to paint events. When I get an event from the timer, I would
just tell wx that part of the window needs redrawing, and depend on it
to give me a paint even when nothing of higher priority needs to be
done.
I've seen this kind of logic recommended in other GUI tookits. Is it a
good idea in wxPython, and, if so, how does one do it?

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


Re: wxPython - drawing without paint event

2007-08-11 Thread glenn . chappell
On Aug 11, 3:31 am, Bjoern Schliessmann  wrote:
>  [EMAIL PROTECTED] wrote:
> > On a related topic, it seems like it would be nice to do *all*
> > drawing in
> > response topaintevents. When I get aneventfrom the timer, I
> > would just tell wx that part of the window needs redrawing, and
> > depend on it to give me apainteven when nothing of higher
> > priority needs to be done.
>
> One nice strategy from an example in "wxPython in Action" is the
> following:
>
> * the frame has Draw methods that draw into a BufferedDC, which is
> chained to a bitmap member
>
> * inside thepaintmethod, the bitmap member is drawn to screen

Okay, but how do I tell wx that it needs to send me a paint event?

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


Re: Distinguishing attributes and methods

2007-12-08 Thread Glenn Hutchings
On Dec 8, 7:44 pm, MonkeeSage <[EMAIL PROTECTED]> wrote:
> I think it muddies the water to say that a.a() and a.a are the same
> thing--obviously they are not.

A thing is not what it is;
A thing is what it does.
This is the Way of the Duck.

-- Basho (in his "3 extra syllables" phase)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUI development with 3D view

2007-12-11 Thread Glenn Hutchings
On Dec 11, 1:58 am, gsal <[EMAIL PROTECTED]> wrote:
> If all you need to do is display a bunch of arrows, as you mention,
> the easiest thing to do might be to use Visual Python.  It is
> extremely easy to use.

Another option, if your app is data-driven, is to check out the
Visualization Toolkit (VTK) at http://www.vtk.org.  It also has 3D
graphics and a Python interface.

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


errno 22 instead of errno 2

2009-01-27 Thread Glenn Linderman

open("c:\abc","rb")

This simple one-line script, produces errno 22 on Python 2.6, but errno 
2 on Python 2.5.2


Is this an unintentional regression?  Or is this an intentional bug fix?

The file doesn't exist (errno 2) but I guess on Windows it is also 
somewhat an invalid file name (errno 22).


Yes, I'm aware that \a is ASCII 007.  Using a valid, non-existent file 
name produces errno 2 on both versions.


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: Tutorial on working with Excel files in Python (without COM and cross platform!) at PyConUS 2009

2009-01-31 Thread Glenn Linderman
On approximately 1/27/2009 5:19 PM, came the following characters from 
the keyboard of Chris Withers:

Hi All,

Too many people in the Python community think the only way to work with
Excel files in Python is using COM on Windows.

To try and correct this, I'm giving a tutorial at this year's PyCon in
Chicago on Wednesday, 25th March that will cover working with Excel
files in Python using the pure-python libraries xlrd, xlwt and xlutils.

I'll be looking to cover:

- Reading Excel Files

  Including formatting, unicode dates and formulae.

- Writing Excel Files

  Including formatting with easyxf and things like freeze pains, print
  areas, etc

- Filtering Excel Files

  A run through on the structure of xlutils.filter and some examples to
  show you how it works.

- Workshop for your problems

  I'm hoping anyone who attends will get a lot out of this! If you're
  planning on attending and have a particular problem you'd like to work
  on in this part of the tutorial, please drop me an email and I'll try
  and make sure I come prepared!

All you need for the tutorial is a working knowledge of Excel and
Python, with a laptop as an added benefit, and to be at PyCon this year:

http://us.pycon.org

I look forward to seeing you all there!



Good luck with the tutorial.  I can't use xlrd because it doesn't 
support comments.  So I use Open Office basic macros to transform the 
data into a usable form.  At least it is way faster than COM, and 
(although I'm using Windows) I think it could be done on Linux.


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to detect if a dictionary has been modified ?

2008-11-23 Thread Glenn Linderman
On approximately 11/23/2008 1:40 AM, came the following characters from 
the keyboard of Steven D'Aprano:

On Sun, 23 Nov 2008 01:18:17 -0800, bearophileHUGS wrote

Stef Mientki:


I would like to detect if a dictionary has been changed. So I would
like to have a modified-flag.
  

A solution is of course to create a SDict class, that works like a
normal dict, and also watches for changes and has an extra boolean
attribute.



What does the S stand for?

Untested and possibly incomplete:

def factory(methodname, cls=dict, flag=True):
def method(self, *args, **kwargs):
self.modified = flag
return getattr(cls, methodname)(self, *args, **kwargs)
return method


class SDict(dict):
__init__ = factory('__init__', flag=False)
__setitem__ = factory('__setitem__')
__delitem__ = factory('__delitem__')
clear = factory('clear')
pop = factory('pop')
popitem = factory('popitem')
setdefault = factory('setdefault')
update = factory('update')
  


Interesting technique.  I must point out, though, that it doesn't 
indicate if a dict has been changed, only that potentially changing 
operations have been performed.  So it really depends on what Stef 
originally meant by changed, and perhaps what is meant by == :)


x = {'a', 3}
x['a'] = 3

Whether x has been changed by the second statement is the open 
question.  The above code would declare it has, but most people, when 
shown before and after copies of the dict, with declare it hasn't.


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: how to detect if a dictionary has been modified ?

2008-11-23 Thread Glenn Linderman
On approximately 11/23/2008 9:50 AM, came the following characters from 
the keyboard of Arnaud Delobelle:

Glenn Linderman <[EMAIL PROTECTED]> writes:

  

On approximately 11/23/2008 1:40 AM, came the following characters
from the keyboard of Steven D'Aprano:


On Sun, 23 Nov 2008 01:18:17 -0800, bearophileHUGS wrote
  

Stef Mientki:



I would like to detect if a dictionary has been changed. So I would
like to have a modified-flag.
  
  

A solution is of course to create a SDict class, that works like a
normal dict, and also watches for changes and has an extra boolean
attribute.



What does the S stand for?

Untested and possibly incomplete:

def factory(methodname, cls=dict, flag=True):
def method(self, *args, **kwargs):
self.modified = flag
return getattr(cls, methodname)(self, *args, **kwargs)
return method


class SDict(dict):
__init__ = factory('__init__', flag=False)
__setitem__ = factory('__setitem__')
__delitem__ = factory('__delitem__')
clear = factory('clear')
pop = factory('pop')
popitem = factory('popitem')
setdefault = factory('setdefault')
update = factory('update')
  
  

Interesting technique.  I must point out, though, that it doesn't
indicate if a dict has been changed, only that potentially changing
operations have been performed.  So it really depends on what Stef
originally meant by changed, and perhaps what is meant by == :)

x = {'a', 3}



You mean x = {'a': 3}!
  


Indeed I did, thanks for the correction.


x['a'] = 3

Whether x has been changed by the second statement is the open
question.  The above code would declare it has, but most people, when
shown before and after copies of the dict, with declare it hasn't.



Good point.  What about

  

d = {1: []}
d[1].append(2)



Has d changed or not?
  


Which just goes to show that the SDict implementation above is, as 
suspected by the author, incomplete for the purpose of detecting all 
changes to the dict, as well as detecting some that might not be 
perceived as changes.



--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


CherryPy vs Bluehost

2008-11-23 Thread Glenn Linderman
So, I'm locked into a Bluehost contract for a couple years.  Was using 
Perl when I signed up.  Only took a few hours to get my site moved from 
my previous host, also cPanel based... a few tweaks and it was running.  
They seem to be OK, but their help forums are pretty sparse... no 
references to cherrypy there...


So I'm wondering if anyone can tell me the best (or only) way to 
configure cherrypy to run on bluehost.  I've read the cherrypy wiki 
about various ways to configure cherrypy to run behind Apache, which 
bluehost uses, but it seemed like the methods required access to the 
main apache configuration file, rather than just .htaccess.  I can only 
tweak .htaccess, with my account, so far as I know.


I'm also interested in how to set up cherrypy to work on Google App 
Engine.  I'm happy to poke around and try things, if necessary, but if 
there are pages describing these things, it could save time.  There's a 
release note that says it does, but not how to do such an installation.


I've got most of my site running locally using cherrypy now, would like 
to extend it in various ways, and I like the cherrypy model of doing 
things, better than having index.cgi files scattered around, and forms 
referencing bunches of .cgi files.



P.S.

The cherrypy-users Google group moderator must be on vacation... I tried 
posting there a couple days ago, and so far my post is still held for 
moderation, I guess.  Emailed the group owner... no response yet... it 
_is_ holiday time, of course.


Anyway, if anyone has an active cherrypy-users account and can repost 
this there if that would bring more enlightened responses, I'd 
appreciate that; I can see that group, just not post, yet.


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: Installing python 2.6 on Vista

2008-11-23 Thread Glenn Linderman
On approximately 11/23/2008 9:17 PM, came the following characters from 
the keyboard of GALLOWAY Stuart J (SVHM):


I accept that this may be essentially a VISTA problem.



So, upgrade to XP, until Microsoft fixes Vista!  I've got 3 versions of 
Python running here on XP!  No problems installing!


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: Installing python 2.6 on Vista

2008-11-23 Thread Glenn Linderman
On approximately 11/23/2008 9:17 PM, came the following characters from 
the keyboard of GALLOWAY Stuart J (SVHM):


I would strongly recommend that an official PORTABLE python for 
windows should be a standard distribution so we can bypass all the 
windows rubbish if we want to.




Sorry about the other answer!  I couldn't resist, though.  I bought and 
returned a laptop computer with Vista, because it wouldn't even do 
dialup!  The diagnostic software would dial the modem, but Vista didn't 
even try!  There were other problems too, but what use is a laptop that 
can't dial the modem, when dialup is all that is available?  And yes, I 
spent the obligatory 6 hours on the phone with the support people before 
returning it... of my vacation time, no less!


The next 4 laptops I bought have XP!

But, hey, a portable version of Python would be nice!  Would probably 
make the job of the various packagers that make .exe files easier, too!


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: what's so difficult about namespace?

2008-11-25 Thread Glenn Linderman
On approximately 11/25/2008 11:01 PM, came the following characters from 
the keyboard of Gene:

On Nov 26, 1:29 am, Xah Lee <[EMAIL PROTECTED]> wrote:
  

comp.lang.lisp,comp.lang.functional,comp.lang.perl.misc,comp.lang.python,co­mp.lang.java.programmer

2008-11-25

Recently, Steve Yegge implemented Javascript in Emacs lisp, and
compared the 2 languages.

http://steve-yegge.blogspot.com/http://code.google.com/p/ejacs/

One of his point is about emacs lisp's lack of namespace.

Btw, there's a question i have about namespace that always puzzled me.

In many languages, they don't have namespace and is often a well known
sour point for the lang. For example, Scheme has this problem up till
R6RS last year. PHP didn't have namespace for the past decade till
about this year. Javascript, which i only have working expertise,
didn't have namespace as he mentioned in his blog. Elisp doesn't have
name space and it is a well known major issue.

Of languages that do have namespace that i have at least working
expertise: Mathematica, Perl, Python, Java. Knowing these langs
sufficiently well, i do not see anything special about namespace. The
_essence_ of namespace is that a char is choosen as a separator, and
the compiler just use this char to split/connect identifiers.
Although i have close to zero knowledge about compiler or parser, but
from a math point of view and my own 18 years of programing
experience, i cannot fathom what could possibly be difficult of
introducing or implementing a namespace mechanism into a language. I
do not understand, why so many languages that lacks so much needed
namespace for so long? If it is a social problem, i don't imagine they
would last so long. It must be some technical issue?

Could any compiler expert give some explanation?

Thanks.

  Xah
∑http://xahlee.org/

☄



When multiple existing systems are combined, namespaces provide a
quick way to prevent name clashes.


While the above is true, and is a benefit of name spaces, it appears the 
OP understands that issue, and is asking why languages without 
namespaces don't add them.


Speaking as someone who has written a few small compiler 
implementations, I'll just point out that when doing a particular 
implementation, there are often times more interesting or pressing needs 
to be achieved by the implementation.


Many languages have other scoping techniques that limit the need for 
global names, thus sidestepping the need for explicit namespaces, by 
reducing their benefits.


Some operating systems have limited the allowable length of global 
(linkable) names, especially in the early days of a computing platform 
(be it the early days of mainframes, minicomputers, or microcomputers 
[now called personal computers, and more powerful than many of the early 
mainframes]), which led to corresponding limits in the languages 
available on such systems.


And, absent namespaces, the user  is not left totally without 
alternative.  Many languages place no or large limits on identifier 
length, so namespace can be simulated by using "module prefixes".  When 
it is known that namespaces are not available, large scale systems 
written in those languages usually have a coding standard that suggests 
using a prefix on all global names for each separable unit of the 
program.  The team of programmers for each separable program unit, then, 
is free to innovate with names within the subset of all possible names 
having the assigned, negotiated, or claimed prefix for their global 
names.  Non-global names are usually not required to have the prefix, as 
scoping rules limit the visibility of those names, although, depending 
on the language, it may be decided that certain non-global names still 
use the prefix for some sort of consistency.


Languages that have limited length variable names (some versions of 
Basic are restricted to single character names; some versions of other 
languages have limited variables names to other lengths -- thinking 
back, 3, 6, 8, and 31 come to mind -- either in total length or 
significant length) are harder mediums in which to develop large-scale 
projects.  Newer versions of languages containing most of the 
length-limited-names tend to increase the allowable length, and/or 
introduce namespaces, or modules (which oftentimes produces multiple 
namespaces as a side-effect).


Multi-purpose languages today are mostly designed to cross-platform, 
have modular compilation facilities necessitating linking of global 
names, and recognize the needs of separate compilation, linking, and 
name collisions, and provide some mechanism for avoiding name 
collisions, either namespaces, or modules that provide namespaces.  Most 
operating systems and linkers provide for long names.  Life is good.  
There are still throwbacks, and still small applications, and still 
languages that don't offer such facilities.


--
Glenn -- http://nevcal.com/
===

Re: Multiple Versions of Python on Windows XP

2008-12-01 Thread Glenn Linderman
On approximately 12/1/2008 11:05 PM, came the following characters from 
the keyboard of Martin v. Löwis:

Is there some way to specify a default version in such a way that it can
be changed as necessary?



What do you mean by "default version"?

There is the version that is associated with the .py/.pyc extensions
at any point in time; you can change these by re-running the respective
installers from add-and-remove-programs. In a well-managed installation,
only one Python installation would have the "Register Extensions"
feature selected; to then change the default, one would unselect the
feature in one version, and reselect it in a different. If only the
default installation procedure was ever used, re-running the installer
in "Repair" mode (from ARP) will also restore the extension
associations.


That seems a lot more cumbersome than just using the command line to 
change the ftype and assoc a bit.  Here's how I set up my computer, for 
multiple versions.  Now to change the "default", I just use the assoc 
command to change the association for .py to one of the three listed 
ftypes.  Simple and quick.


c:\>ftype Python25.File
ftype Python25.File
Python25.File="C:\Python25\python.exe" "%1" %*

c:\>ftype Python26.File
ftype Python26.File
Python26.File="C:\Python26\python.exe" "%1" %*

c:\>ftype Python30.File
ftype Python30.File
Python30.File="C:\Python30\python.exe" "%1" %*

c:\>assoc .py
assoc .py
.py=Python25.File


It would be nice if the ftypes were version specific as created by the 
installer; IIRC, I created the above three from the ftype Python.File as 
I installed each version.


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: Multiple Versions of Python on Windows XP

2008-12-02 Thread Glenn Linderman
On approximately 12/1/2008 11:29 PM, came the following characters from 
the keyboard of Martin v. Löwis:

It would be nice if the ftypes were version specific as created by the
installer; IIRC, I created the above three from the ftype Python.File as
I installed each version.



That's a good idea; please submit a wish list item to bugs.python.org.
There may be issues (such as people relying on this being Python.File),
but I can't see any problems off-hand.

Regards,
Martin
  


OK, Issue 4485 created.  My first one, so let me know if I goofed.  I 
elaborated a bit from the original email, upon reflection.  Seemed 
useful, but also seemed complex by the time I got done.


I don't really have a clue what the uninstaller should do with these; 
nor have I fiddled to know if it presently removes Python.File.  I 
suppose it should delete them, if and only if the ftype and assoc have 
the same content as was created by the corresponding version installation.


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: Simple ini Config parser examples needed

2008-12-02 Thread Glenn Linderman
On approximately 12/2/2008 1:31 PM, came the following characters from 
the keyboard of Chris Rebert:

On Tue, Dec 2, 2008 at 1:18 PM, RON BRENNAN <[EMAIL PROTECTED]> wrote:
  

Hello,

I have a very simple ini file that I needs parsed.  What is the best way I
can parse an ini file that doesn't include sections?

As in:



Since it appears that ConfigParser requires at least one section
header, I'll assume the file starts with the following line:

[main]
  

person=tall
height=small
shoes=big


Thats it.  Can anyone help me?



Completely untested:

import ConfigParser
config = ConfigParser.RawConfigParser()
config.readfp(open("path/to/file.cfg"))
config.get("main", "height") #==> "small"

Cheers,
Chris
  


Of course the OP question was that the line you assume isn't there.  But 
if the ini is simple, maybe it is short enough to read into a string, 
then prepend the line, then parse with ConfigParser.


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: Simple ini Config parser examples needed

2008-12-02 Thread Glenn Linderman
On approximately 12/2/2008 3:22 PM, came the following characters from 
the keyboard of Chris Rebert:

On Tue, Dec 2, 2008 at 2:51 PM, Glenn Linderman <[EMAIL PROTECTED]> wrote:
  

On approximately 12/2/2008 1:31 PM, came the following characters from the
keyboard of Chris Rebert:


On Tue, Dec 2, 2008 at 1:18 PM, RON BRENNAN <[EMAIL PROTECTED]>
wrote:

  

Hello,

I have a very simple ini file that I needs parsed.  What is the best way
I
can parse an ini file that doesn't include sections?



*Bangs head against wall repeatedly*
I merely glossed the question and missed that all-important second
sentence! fsck!
My apologies, I shouldn't write email before having coffee :)
Fortunately Tim followed quickly with the correct answer to the OP.
  


Tim provided a correct-looking answer, albeit somewhat complex, as it 
doesn't reuse the logic in the ConfigParser.  That's why I suggested yet 
another alternative, yet left one key item off myself (added below).



As in:


Since it appears that ConfigParser requires at least one section
header, I'll assume the file starts with the following line:

[main]

  

person=tall
height=small
shoes=big


Thats it.  Can anyone help me?



Completely untested:

import ConfigParser
config = ConfigParser.RawConfigParser()
config.readfp(open("path/to/file.cfg"))
config.get("main", "height") #==> "small"

Cheers,
Chris

  

Of course the OP question was that the line you assume isn't there.  But if
the ini is simple, maybe it is short enough to read into a string, then
prepend the line, then parse with ConfigParser.



And I meant to add "parse with ConfigParser by passing the combined 
string in via StringIO.


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: Multiple Versions of Python on Windows XP

2008-12-03 Thread Glenn Linderman
On approximately 12/3/2008 8:51 AM, came the following characters from 
the keyboard of Colin J. Williams:

Martin v. Löwis wrote:

What changes are made to the registry?

For a complete list, see Tools/msi/msi.py in the source tree.

I have scanned the file:
http://svn.python.org/projects/python/branches/py3k/Tools/msi/msi.py

I don't find anything that addresses this issue.


Read the add_registry function. You may need to first understand
how the Registry table in an MSI file works.


I am seeking some mechanism such that any of Python 2.5, Python 2.6 or
Python 2.6 can be chosen as the currently active version.


If Glenn Lindermann's answer doesn't help, you need to explain:
what is a "currently active version"? How is one Python version
more active than any other?

I was hoping that there is some simpler way than the "Repair" 
procedure.


See Glenn Lindermann's answer.

It would be good to be more specific with such statements: what 
troubles

specifically? If I play dumb, I'd say "of course - windows explorer
doesn't support editing Python files; you need a text editor".

Yes, I should have been clearer.  The PyScripter application locks up
and must be killed, using the Task Manager.


I think you need to report that to the PyScripter authors as a bug.
I can't imagine how the "currently active version" can affect what
PyScripter does.

Regards,
Martin


Martin,

Many thanks for your responses.  Yes,
Glen Lindermann's suggestion seems to
meet the need.

It's been a while since I've looked at
DOS and I didn't remember fType or assoc.


The equivalent of those commands is available via Windows Explorer, 
Tools / Folder Options, File Types, scroll-scroll-scroll your way to 
.py, Click Advanced, fiddle, copy paste apply, and other twaddle.  A 
perfect example of why not everything should be done via GUI interfaces, 
or at least why this is an extremely poor GUI interface.


GUI designers should count the command line keystrokes, and make sure 
their interface is shorter, otherwise they are a failure.



Michel Claveau suggests VirtualBox, this
seems a big hammer to kill
this particular fly.

It's interesting that each install sets
up a Python.File variable in the registry.

It's a pity that this can't be used to achieve this more simply.


Martin seems willing to entertain the idea of future Windows installers 
doing something more brilliant in this area, for those that wish to 
switch between multiple installed versions, as he asked for a tracking 
issue to be created, which I did.


Whether it will be exactly my technique, or something further improved, 
time will tell.  But that will only apply to versions released after 3.0 
and 2.6.1 (unless he has already coded it into the release, but I doubt 
he had time, or wishes to destabilize or delay these releases).


Anyway, if you remember the arcane techniques for copy/paste in CMD 
prompt windows (Alt-space or click the "system" icon in the upper left 
of the CMD prompt window), and go from there, then setting up the 
multiple ftypes becomes a bit easier, perhaps.



Best wishes,

Colin W. 




--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: Multiple Versions of Python on Windows XP

2008-12-04 Thread Glenn Linderman
On approximately 12/4/2008 5:29 AM, came the following characters from 
the keyboard of Colin J. Williams:



Glenn Linderman wrote:


The equivalent of those commands is available via Windows Explorer, 
Tools / Folder Options, File Types, scroll-scroll-scroll your way to 
.py, Click Advanced, fiddle, copy paste apply, and other twaddle.  
Yes, but what's needed is a further level of indirection.  Currently, 
this allows .py to be associated with a particular editor.  It would 
be great if there were some way of associating "Python.File", which is 
created in the install process, with a particular editor.  Then, one 
is left with associating "Python.File" with a given version of 
Python.  Meanwhile, your suggestion provides a workaround.


Sure, it is possible to simply change the Python.File ftype -- just 
issue the command


ftype Python.File="C:\PythonNN\python.exe" "%1" %*

for NN = 25, 26 or 30 or whatever.  But that is longer and harder to 
remember and type than the assoc which is why chose to keep three ftypes 
around and switch between them with the assoc command.  But if you put 
them in a batch file, or shortcut, the length and complexity wouldn't be 
as much of an issue.  But changing one or changing the other is roughly 
equivalent... ftype is an extra level of indirection over assoc... and 
it is designed to allow programs that handle multiple extensions to not 
proliferate the full command for each extensions.  For example, a 
multi-image-format image program, could use something like:


assoc .jpg=ImageProg.File
assoc .gif=ImageProg.File
assoc .tif=ImageProg.File
ftype ImageProg.file="C:\Program Files\ImageProg\ImageProg.exe" "%1" %*

In that situation, because of the potentially large number of 
extensions, changing the assoc isn't equivalent to changing the ftype, 
but for Python, I'm unaware of it needing to handle multiple extensions 
from the command line or via double clicking in Explorer, so was 
exploiting the extra level of indirection to save typing, and make the 
command simpler to remember.


Not sure what your reference to an editor is about. ftype only fiddles 
with the Shell Open command; if you want to do tricks with different 
editors for different versions of Python, then you have to fiddle the 
Shell Edit command; this can be done with clever manipulation of the 
registry... it would be straightforward to create a .reg file that swaps 
both the Shell Open and Shell Edit commands for different versions of 
Python, if that is useful... and maybe it is if you use an IDE of some 
sort.  Since I just use emacs to edit .py files, I ignored the Shell 
Edit command.  Instead I have a Shell Emacs command that is set up to 
apply to all file types, and is available via the context menu from 
Windows Explorer... but I use that not only for different versions of 
Python, but source code in other languages, and text files of all types.


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: length of a tuple or a list containing only one element

2009-01-07 Thread Glenn Linderman
On approximately 11/3/2008 11:55 AM, came the following characters from 
the keyboard of Tim Chase:

For making a literal tuple, parentheses are irrelevant; only the
commas matter:
I don't think I'd go so far as to say that the parentheses around 
tuples are *irrelevant*...maybe just relevant in select contexts


 >>> def foo(*args):
 ... for i, arg in enumerate(args):
 ... print i, arg
 ...
 >>> foo(1,2)
 0 1
 1 2
 >>> foo((1,2))  # these parens are pretty important :)
 0 (1, 2)

pedantically-grinning-ducktyping-and-running-ly yers,


I'll see your pedantry and raise you one:
 >>> foo()
 >>> foo(())
0 ()


And just because another "tuples without parens" case exists:

 >>> foo(,)
   File "", line 1
 foo(,)
 ^
 SyntaxError: invalid syntax

To maintain the poker theme, I'd say "You raised, and I call" but my 
call fails :-P


-tkc



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



I'm glad you guys had this thread, which I read with interest and some 
amusement back when it happened.  I am an experienced programmer, but a 
relative newcomer to Python.


And so it was, the last couple nights, that I spent much time looking 
for why my CherryPy configuration didn't work, and after much searching 
of the CherryPy documentation for a tracing technique (which I still 
wish I could find), I finally hacked the code to add an extra pprint.  
Even after that, I focused on the wrong data in the pprint output.


At long last, I discovered that somehow my hash-of-hashes was mostly a 
hash-of-hashes, but there was a tuple in there that contained a hash 
too!  Now how did that get in there?


conf['/path'] = {
   'item1': 'value1',
   'item2': 'value2',
   },

So I was focusing on the items and values of the pprint, and they were 
all correct.  But this tuple clearly didn't belong, but my brain was 
expecting that tuples would be surrounded by () in source...


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


How to create Pygments extension for Sphinx

2008-10-14 Thread Glenn Hutchings
Hi there Pythonistas...

I'm writing documentation for a non-Python program using Sphinx
(http://sphinx.pocoo.org), which is great.  The program has an input
file syntax suitable for highlighting using Pygments (http://
pygments.org), but, obviously, Pygments knows nothing about it.  I've
created a Pygments lexer which should highlight things, but how do I
tell Pygments about the new lexer, short of manually adding the Python
source to the Pygments "lexers" directory (clearly the Wrong Thing)?

I've scoured Sphinx, Pygments and setuptools documentation, and
seemingly the only way is to register a setuptools 'entry point' in
the setup() function -- but that implies I'm installing a Python
package, which I'm not.  Do I have to create one, or is there another
way?

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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-24 Thread Glenn Linderman
On approximately 10/24/2008 1:09 PM, came the following characters from 
the keyboard of Rhamphoryncus:

On Oct 24, 1:02 pm, Glenn Linderman <[EMAIL PROTECTED]> wrote:
  

On approximately 10/24/2008 8:42 AM, came the following characters from
the keyboard of Andy O'Meara:



Glenn, great post and points!
  

Thanks. I need to admit here that while I've got a fair bit of
professional programming experience, I'm quite new to Python -- I've not
learned its internals, nor even the full extent of its rich library. So
I have some questions that are partly about the goals of the
applications being discussed, partly about how Python is constructed,
and partly about how the library is constructed. I'm hoping to get a
better understanding of all of these; perhaps once a better
understanding is achieved, limitations will be understood, and maybe
solutions be achievable.

Let me define some speculative Python interpreters; I think the first is
today's Python:

PyA: Has a GIL. PyA threads can run within a process; but are
effectively serialized to the places where the GIL is obtained/released.
Needs the GIL because that solves lots of problems with non-reentrant
code (an example of non-reentrant code, is code that uses global (C
global, or C static) variables – note that I'm not talking about Python
vars declared global... they are only module global). In this model,
non-reentrant code could include pieces of the interpreter, and/or
extension modules.

PyB: No GIL. PyB threads acquire/release a lock around each reference to
a global variable (like "with" feature). Requires massive recoding of
all code that contains global variables. Reduces performance
significantly by the increased cost of obtaining and releasing locks.

PyC: No locks. Instead, recoding is done to eliminate global variables
(interpreter requires a state structure to be passed in). Extension
modules that use globals are prohibited... this eliminates large
portions of the library, or requires massive recoding. PyC threads do
not share data between threads except by explicit interfaces.

PyD: (A hybrid of PyA & PyC). The interpreter is recoded to eliminate
global variables, and each interpreter instance is provided a state
structure. There is still a GIL, however, because globals are
potentially still used by some modules. Code is added to detect use of
global variables by a module, or some contract is written whereby a
module can be declared to be reentrant and global-free. PyA threads will
obtain the GIL as they would today. PyC threads would be available to be
created. PyC instances refuse to call non-reentrant modules, but also
need not obtain the GIL... PyC threads would have limited module support
initially, but over time, most modules can be migrated to be reentrant
and global-free, so they can be used by PyC instances. Most 3rd-party
libraries today are starting to care about reentrancy anyway, because of
the popularity of threads.



PyE: objects are reclassified as shareable or non-shareable, many
types are now only allowed to be shareable.  A module and its classes
become shareable with the use of a __future__ import, and their
shareddict uses a read-write lock for scalability.  Most other
shareable objects are immutable.  Each thread is run in its own
private monitor, and thus protected from the normal threading memory
module nasties.  Alas, this gives you all the semantics, but you still
need scalable garbage collection.. and CPython's refcounting needs the
GIL.
  


Hmm.  So I think your PyE is an instance is an attempt to be more 
explicit about what I said above in PyC: PyC threads do not share data 
between threads except by explicit interfaces.  I consider your 
definitions of shared data types somewhat orthogonal to the types of 
threads, in that both PyA and PyC threads could use these new shared 
data items.


I think/hope that you meant that "many types are now only allowed to be 
non-shareable"?  At least, I think that should be the default; they 
should be within the context of a single, independent interpreter 
instance, so other interpreters don't even know they exist, much less 
how to share them.  If so, then I understand most of the rest of your 
paragraph, and it could be a way of providing shared objects, perhaps.


I don't understand the comment that CPython's refcounting needs the 
GIL... yes, it needs the GIL if multiple threads see the object, but not 
for private objects... only one threads uses the private objects... so 
today's refcounting should suffice... with each interpreter doing its 
own refcounting and collecting its own garbage.


Shared objects would have to do refcounting in a protected way, under 
some lock.  One "easy" solution would be to have just two types of 
objects; non-shared private objects in a thread, and global shared 
objects; access to global shared objects would require grab

Re: 2.6, 3.0, and truly independent intepreters

2008-10-30 Thread Glenn Linderman
On approximately 10/30/2008 6:26 AM, came the following characters from 
the keyboard of Jesse Noller:

On Wed, Oct 29, 2008 at 8:05 PM, Glenn Linderman <[EMAIL PROTECTED]> wrote:
  

On approximately 10/29/2008 3:45 PM, came the following characters from the
keyboard of Patrick Stinson:


If you are dealing with "lots" of data like in video or sound editing,
you would just keep the data in shared memory and send the reference
over IPC to the worker process. Otherwise, if you marshal and send you
are looking at a temporary doubling of the memory footprint of your
app because the data will be copied, and marshaling overhead.
  

Right.  Sounds, and is, easy, if the data is all directly allocated by the
application.  But when pieces are allocated by 3rd party libraries, that use
the C-runtime allocator directly, then it becomes more difficult to keep
everything in shared memory.

One _could_ replace the C-runtime allocator, I suppose, but that could have
some adverse effects on other code, that doesn't need its data to be in
shared memory.  So it is somewhat between a rock and a hard place.

By avoiding shared memory, such problems are sidestepped... until you run
smack into the GIL.



If you do not have shared memory: You don't need threads, ergo: You
don't get penalized by the GIL. Threads are only useful when you need
to have that requirement of large in-memory data structures shared and
modified by a pool of workers.


The whole point of this thread is to talk about large in-memory data 
structures that are shared and modified by a pool of workers.


My reference to shared memory was specifically referring to the concept 
of sharing memory between processes... a particular OS feature that is 
called shared memory.


The need for sharing memory among a pool of workers is still the 
premise.  Threads do that automatically, without the need for the OS 
shared memory feature, that brings with it the need for a special 
allocator to allocate memory in the shared memory area vs the rest of 
the address space.


Not to pick on you, particularly, Jesse, but this particular response 
made me finally understand why there has been so much repetition of the 
same issues and positions over and over and over in this thread: instead 
of comprehending the whole issue, people are responding to small 
fragments of it, with opinions that may be perfectly reasonable for that 
fragment, but missing the big picture, or the explanation made when the 
same issue was raised in a different sub-thread.


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: Code not work - DESPERATE HELP :(

2008-10-30 Thread Glenn Linderman
On approximately 10/30/2008 2:13 PM, came the following characters from 
the keyboard of Bill McClain:

On 2008-10-30, fx5900 <[EMAIL PROTECTED]> wrote:

  

   I just went to go and get a coffee when i noticed a email, thought it was
just usual spam. Read your message, and it worked. it was because i did not
put they 'python' keyword infront. How did u figure it out?



It is some problem with the DOS box on Windows. I believe the standard input
and output get lost somehow. I just encountered it myself. Using the "python"
command is not required on other platforms--Linux, for example.

If anyone has a more elegant solution I would like to hear it. I hate
documenting "this way on Windows, another way everywhere else..."

-Bill
  


The problem with stdin/stdout is on Windows 2000 (and maybe the earlier 
NT?).  But not on XP or AFAIK Vista.


It only occurs when a program is executed indirectly using the file 
associations instead of directly via the command line.


File associations, are the Windows "let's do it a different way" 
alternative for Unix she-bang lines (#!/path/to/python).


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: Windows DOS box redirection

2008-10-31 Thread Glenn Linderman
On approximately 10/31/2008 5:06 AM, came the following characters from 
the keyboard of Bill McClain:

On 2008-10-31, Glenn Linderman <[EMAIL PROTECTED]> wrote:
  
The problem with stdin/stdout is on Windows 2000 (and maybe the earlier 
NT?).  But not on XP or AFAIK Vista.

It only occurs when a program is executed indirectly using the file 
associations instead of directly via the command line.

File associations, are the Windows "let's do it a different way" 
alternative for Unix she-bang lines (#!/path/to/python).

Can you elaborate on this? 


What I reported is what I remembered from when XP came out.  Seems like

Testing now indicates that it doesn't work so well on XP at this point.

That either means that my memory was faulty, or that some XP update 
broke it again.


What I remember for sure, is that this is not a new problem; that it was 
introduced in some version of Windows, that it was fixed in some later 
version of Windows.  The whole issue totally predates Vista, so it would 
have had to have been the introduction of 2000 or XP that fixed it.  Or 
a service pack.


Here is what Google helped me find that M$ remembers:  
http://support.microsoft.com/kb/321788  (Ah, I see Tim found this too)


Looks like it was broken in both 2000 and XP, and fix in both via a 
service pack or hot fix, but seems to now be broken again?


Creating the registry setting mentioned in this kb article didn't 
(immediately) solve the problem.  Next time I reboot, I'll try to 
remember to test this again.


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: Windows DOS box redirection

2008-10-31 Thread Glenn Linderman

A little bit ago, I wrote:

Creating the registry setting mentioned in this kb article didn't 
(immediately) solve the problem.  Next time I reboot, I'll try to 
remember to test this again.


It occurred to me to create a new CMD Prompt (yes, it is not a "DOS box" 
in these versions of Windows) after creating the InheritConsoleHandles 
registry value, and it works then.


XP, latest patches.

The old CMD Prompt still fails.

--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking


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


Re: Windows DOS box redirection

2008-10-31 Thread Glenn Linderman
On approximately 10/31/2008 9:22 PM, came the following characters from 
the keyboard of Dennis Lee Bieber:

On Fri, 31 Oct 2008 12:14:36 -0700, Glenn Linderman <[EMAIL PROTECTED]>
declaimed the following in comp.lang.python:

  

A little bit ago, I wrote:


Creating the registry setting mentioned in this kb article didn't 
(immediately) solve the problem.  Next time I reboot, I'll try to 
remember to test this again.
  
It occurred to me to create a new CMD Prompt (yes, it is not a "DOS box" 
in these versions of Windows) after creating the InheritConsoleHandles 
registry value, and it works then.


XP, latest patches.

The old CMD Prompt still fails.



A tad confusing -- do you mean the previous console window is
misbehaving, but creating a new console window is working? That behavior
I can believe, as the console probably read the relevant registry
entries on start-up, hence did not see any changes (same thing occurs if
you edit environment variables using My Computer/Properties).
  


Correct.  Creating a new CMD window after making the registry 
modification worked, while the CMD window created before the registry 
modification continued to fail.



But be careful otherwise... WinXP still has command.com

Microsoft(R) Windows DOS
(C)Copyright Microsoft Corp 1990-2001.

C:\DOCUME~1\DENNIS~1>

besides the more modern cmd.exe

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Dennis Lee Bieber>

So "old CMD Prompt" could be mistaken to refer to the ancient
command.com 
  


Indeed it does, and could, but that isn't what I meant.  I didn't test 
at all with command.com.



--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: push-style templating - an xml-like way to process xhtml

2008-11-03 Thread Glenn Linderman
ther desired 
uses.  There is nothing in the HTML syntax that prevents the use of an 
attribute similar to ID, perhaps called PyMeld, such that PyMeld="whatever" id="something-HTMLish" href="..."> could be used in 
the HTML.  The PyMeld controller would have to parse these, and 
potentially could remove them from the output, to avoid confusing 
browsers (but most browsers would just ignore them anyway).


It would be nice if a collection of static data items could be provided, 
such that the controller code could transform the presentation markup 
into browser-displayable data, without the application. Such a generic 
controller for each modality, together with files of data samples, could 
help in the negotiations between designer and coder.  Using 
StringTemplate for an example again, the attribute layout (I forget what 
term was used for that) that is the specification of what the model must 
provide and what the view has available is interesting, and the data 
samples would have to provide a subset of all the attributes in the 
layout, and the generic controller the code for putting them together.


Most designers are unlikely, in my opinion, to be able to create a 
StringTemplate subtemplate superstructure without the visual feedback of 
generating the modality-specific end-product with which they are 
comfortable.  Available data samples (even if changing due to changing 
requirements and/or negotiations between the view and model development 
teams as requirements get better understood), and a generic controller, 
would seem to allow parallel development of the model and view.



Once you do compare like with like, the 'push/pull' distinction
becomes somewhat irrelevant, as the control code for a PyMeld-based
View could be pushing or it could be pulling. It's up to each
program's developer to decide which way they want to do it - and in a
proper MVC design it should always be pulling.
  


Indeed, I can totally agree that the 'push/pull' distinction is somewhat 
irrelevant, when pull is properly implemented.


I think the push/pull distinction is mostly one of implementation 
convenience.  Certainly the data from the model must be available to the 
view.  If you look at the StringTemplate architecture, which is the one 
promoting 'push', you find that it provides a set of attributes... which 
it calls 'push'... but doesn't require the model to look at them... when 
the model looks at them, that can be considered 'pull'.  The very 
definition of 'push' that Terence describes is simply that "A safe pull 
strategy degenerates to push in the worst case" (his Theorem 4 from the 
mvc.templates.pdf paper).


So while Terence claims that "Pull strategy violates separation" as the 
title of section 7.1, his claim is really that "some implementations of 
a model providing a pull strategy, which observe and make assumptions 
about the order in which a view may do its pulls of individual 
attributes, violate the separation between View and Model."  As long as 
the 'pull' model doesn't have dependencies on the the order in which 
items are pulled, and can provide a consistent set of data regardless of 
that order, it really doesn't matter whether you use push or pull.


The "take away" point is that an easy way to implement the pull 
strategy, is for the model to precalculate and cache all the data needed 
by the view, and provide it as a complete lump of attributes available 
to the view, from which the view may pull the data at its leisure.



A more useful distinction to make is between templating systems that
combine appearance and control, and those that keep them separate, as
this has significant implications when considering which type of
templating system to choose, e.g.:

- how complex the interface is, e.g. Cheetah's interface is larger and
more complex than PyMeld's (even though they do the same thing), which
means a longer learning curve

- how clean the division of responsibility is, e.g. PyMeld separates
HTML markup from Python code, which provides an obvious advantage if
you've got a web designer handling one task and a Python programmer
handling the other, or a likely disadvantage if both tasks are being
handled by a relatively non-technical web designer

- how abstract the program's View implementation is, e.g. a PyMeld-
based View is more abstract than a Cheetah one, as markup and code are
physically separate and are only combined in memory, which means the
logic developer has to work harder in mentally modelling their View
layer's structure and behaviour.


These would certainly be useful measures to make, and like you point 
out, there can be advantages and disadvantages of each approach.


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: Structures

2008-11-03 Thread Glenn Linderman
On approximately 11/3/2008 3:38 PM, came the following characters from 
the keyboard of Paulo J. Matos:

On Mon, Nov 3, 2008 at 10:19 PM, Aaron Brady <[EMAIL PROTECTED]> wrote:
  

On Nov 3, 3:45 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:


"Paulo J. Matos" <[EMAIL PROTECTED]> writes:

  

On Mon, Nov 3, 2008 at 12:32 PM, Ben Finney
<[EMAIL PROTECTED]> wrote:


I'm wondering a more fundamental question: What are structures?
That is, what do *you* mean by that term; without knowing that, an
answer isn't likely to be meaningful.
  

Well, I guess that everyone pretty much gets since it exists in
every other language as struct, or define-structure, or whatever is
the syntax.


Take care with broad sweeping statements about "every other language",
or even "most other languages". They are usually flat-out wrong:
there is a stunning variety of different approaches and concepts in
programming languages, with very little common to even a majority of
them.
  

Yea, verily.  How many languages do you think that is?  Feel free to
count C and C++ as different ones.

"Four shalt thou not count, neither count thou two"
http://en.wikipedia.org/wiki/Holy_Hand_Grenade_of_Antioch#Usage_instructions



Well, I wouldn't dare to say I know a lot of languages but the ones I
do provide mechanisms to define structures / records: C, C++, Scheme,
Common Lisp, Haskell, SML, Ocaml.
This is obviously a minority if you count all available programming
languages in the world, but I would dare to say these cover a lot of
ground.
  


There are languages that do not have structs; but usually there is some 
way to obtain something similar.



However, I wouldn't dare to say Python needs structures to be a good
language, or anything similar. My question was more directed to : if
there aren't structures in Python, what do Pythonists use instead?
(I have seen dicts might be an alternative, but as I said in previous
post, they seem to flexible [making them a canon to shoot a fly, and
they probably lack constant-time access, right?]
  


Dicts have constant time access.  On the other hand, the constant is 
significantly larger than the constant for accessing a C struct.


Note that classes, by default, are based on a contained dict!  There are 
games to be played with slots that can apparently improve that.  I am 
not yet experienced enough with Python to know if a slot is as fast as a 
C struct, but perhaps it is.  You can have both slots and a dict, to get 
both speed and flexibility, or you can eliminate the dict and use slots 
only, but that limits your flexibility.  But structs aren't flexible, 
except at compile time, so that might not be a problem for you.


Another thing I don't know is if slots are as fast as tuples.  Perhaps a 
slots-only class and a tuple might be speed rivals?  But the former is 
mutable, and the latter not.


Perhaps a more experience Python user can answer that question, at least 
for some particular implementation.


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: Structures

2008-11-03 Thread Glenn Linderman
On approximately 11/3/2008 5:28 PM, came the following characters from 
the keyboard of Aaron Brady:

On Nov 3, 5:38 pm, "Paulo J. Matos" <[EMAIL PROTECTED]> wrote:
  

On Mon, Nov 3, 2008 at 10:19 PM, Aaron Brady <[EMAIL PROTECTED]> wrote:


On Nov 3, 3:45 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
  

"Paulo J. Matos" <[EMAIL PROTECTED]> writes:
Take care with broad sweeping statements about "every other language",
or even "most other languages". They are usually flat-out wrong:
there is a stunning variety of different approaches and concepts in
programming languages, with very little common to even a majority of
them.


Yea, verily.  How many languages do you think that is?  Feel free to
count C and C++ as different ones.
  

Well, I wouldn't dare to say I know a lot of languages but the ones I
do provide mechanisms to define structures / records: C, C++, Scheme,
Common Lisp, Haskell, SML, Ocaml.



I don't know even half of those.  What about Perl?  Does anyone know
that?
  


structs in Perl are generally implemented as hashes, which is similar to 
a Python dict.


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: What's your choice when handle complicated C structures.

2008-11-05 Thread Glenn Linderman
On approximately 11/4/2008 5:31 PM, came the following characters from 
the keyboard of Marc 'BlackJack' Rintsch:

On Tue, 04 Nov 2008 16:52:17 -0800, 一首诗 wrote:

  

Now I'm using the upack function of 'struct' module, but it's really
annoying to write fmt strings for complicated structures.

What will be your choice when handling binary structures?



http://construct.wikispaces.com/


Interesting.  It seems to be a bit more capable around the edges than 
unpack, and certainly has a friendlier looking syntax, but I wonder how 
the performance compares to unpack, for the cases they both handle?  
Seems like for cases they both handle, it could be beneficial to compile 
to the equivalent unpack for speed?


Containers look nice, but it seems it would be nice to allow multiple 
targets: Containers, dicts (with a special entry giving the order of the 
fields, perhaps, for reconstruction; maybe that is what a container is, 
already?), namedtuples, all seem to be reasonable alternative targets, 
with different usage tradeoffs, of course.


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: push-style templating - an xml-like way to process xhtml

2008-11-05 Thread Glenn Linderman
On approximately 11/3/2008 2:51 PM, came the following characters from 
the keyboard of has:

On 3 Nov 2008, at 18:18, Glenn Linderman wrote:
  

On approximately 11/3/2008 12:20 AM, came the following characters
from the keyboard of has:


On 2 Nov, 14:06, Tino Wildenhain <[EMAIL PROTECTED]> wrote:
  

"$attr.title$
$if(attr.active)$
$attr.submenu:menuItem()$
$endif$"

This looks ugly to me.


It also looks like an embedded mini-language to me.

At any rate, I think making a 'push/pull' distinction misses the
point.

There are basically three approaches a templating system can use:

1. embed your control logic in your presentation markup,

2. embed your presentation markup in your control logic, or

3. keep the two separate and transform the presentation markup into
some sort of DOM that can then be manipulated by the control code.
[...]
- A Cheetah-based View is implemented as an HTML file with all of the
required control code embedded in it.

- A PyMeld-based View is implemented as an HTML file with id
attributes that indicate which HTML elements should be converted into
object model nodes, *plus* a Python module containing the control
code
that manipulates those nodes when rendering a finished document.

  

It would be nicest to keep the two separate... such that the HTML
could be directly displayed in a browser, albeit with placeholder
data items.



That's what DOM-style templating engines (which StringTemplate
isn't)
generally do: since they leverage the existing HTML element
structure,
the only additions to the HTML that are needed are tag attributes to
indicate which elements should be represented as DOM nodes. Most
allow
you to create a 100% valid HTML/XHTML document, complete with
placeholder text for previewing the template in a browser.
  


Sure.  But DOM-style templating engines, although perhaps clearly handy 
in today's browser-and-internet-centric world, are limited to one view 
modality.


Unless, of course, you target other textual data structures that are, or 
can be made to be, DOM-style.  But I infer here that you are primarily 
referring to a particular DOM, that of internet documents, and that 
other DOMs could be sufficiently different syntactically, that an 
internet-DOM would not apply very easily.




The StringTemplate approach of nested, inherited subtemplates
probably provides more power, and less cut-n-paste redundancy in
development, but provides nothing for the designer to preview until
the whole application is complete and specific data generated.



Not going to argue with that, but if you read my previous post,
StringTemplate barely came into it. 


I did; but the thread was started with a reference to Terence Parr's 
StringTemplate paper.



IMO StringTemplate is closest to
approach 1 above, since it uses a simple embedded language to pull
data from a pre-arranged data structure. 


I would agree with this.


Its only similarity to
approach 3 is that the embedded language isn't powerful enough to
implement all of your View logic in, so you end up having to write
at
least some of your View logic outside of the template, using the
host
language to pull data from the Model layer and massage it into a
format suitable for consumption by a StringTemplate template.
  


Hmm.  One of the things Terence seems to be trying to point out is that 
even though the embedded language of StringTemplate is less than Turing, 
that it is sufficient for Viewing.


The language of StringTemplate does have the ability to make reference 
to model attributes; that is sufficient "to pull data from the Model 
layer".  And the massaging is assigned to the Controller, or a new 
subpiece called the renderer, and is limited to formatting type 
operations on single data items at a time (if I understand it 
correctly).  I've only read a couple StringTemplate papers, I haven't 
played with it yet.



Unfortunately, keeping the two languages separate adds significantly
to the burden of figuring out how to mix them together.



Some embedded templating systems involve one language; others
require
two. 


Indeed; but it is not clear those embedded templating systems involving 
only one language enforce MVC.



e.g. Cheetah-based applications involve two languages: Python
for
the Model, its own HTML-embedded language for the View. OTOH, DOM-
style templating languages should only ever require one language:
there's no logic in the HTML to begin with, so all you need is a
language to manipulate the DOM API, which might as well be the same
language as the rest of your application.
  


And if the app manipulates the DOM API, it again doesn't enforce MVC.


Intermingled/embedded control and presentation (either embedded
print statements, or templating systems), have become popular (in my
opinion) because they do solve the problem of figuring out how do
the mix.



Disagree. Embedded temp

Re: Snippets management

2008-11-05 Thread Glenn Linderman
On approximately 11/5/2008 8:23 PM, came the following characters from 
the keyboard of r:

I don't use one, but why not take a stab at coding one yourself.
Use Tkinter to start, its easy.  well documented
gotta learn GUI somehow


Since you are recommending tkinter, maybe you know what is the state of 
cross-platform (or even single-platform) printing capabilities in Tk 
these days?  Last I heard, there was a plan, but it was nowhere near 
complete.  So I guess the OP is on a mac, so maybe you could reply about 
mac printing capabilities, if you know, but I'm interesting in 
cross-platform printing.


Because of that, I've started learning PyQt, which seems to be 
cross-platform at least for Linux, Mac, and Windows...


--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

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


Re: who to thank for the new RST doc format?

2008-11-18 Thread Glenn Hutchings
On 18 Nov, 08:46, [EMAIL PROTECTED] wrote:
> I am really loving the output, and have started using RST for some
> of my own docs as well.
>
> It's wonderful and I know it was a lot of work on somebody's part
> to think it through and make the changes.
>
> If it was you, Many Thanks!!!

It *is* good, isn't it?  Direct your thanks at the creator of Sphinx
(http://sphinx.pocoo.org).
--
http://mail.python.org/mailman/listinfo/python-list


Re: [ANN] regobj - Pythonic object-based access to the Windows Registry

2009-05-04 Thread Glenn Linderman
On approximately 5/3/2009 7:35 AM, came the following characters from 
the keyboard of Ryan Kelly:

Hi All,

  I've just released the results of a nice Sunday's coding, inspired by
one too many turns at futzing around with the _winreg module.  The
"regobj" module brings a convenient and clean object-based API for
accessing the Windows Registry.



Sounds very interesting, Ryan.  Just a couple questions about the 
dictionary interface.




If a subkey is assigned a dictionary, the structure of that dictionary
is copied into the subkey.  Scalar values become key values, while
nested  dictionaries create subkeys:

  >>> HKCU.Software.MyTests = {"val1":7, "stuff":{"a":1,"c":2,"e":3}}
  >>> [v.name for v in HKCU.Software.MyTests.values()]
  ['val1']
  >>> [k.name for k in HKCU.Software.MyTests.subkeys()]
  ['stuff']
  >>> len(HKCU.Software.MyTests.stuff)
  3

Any other value assigned to a subkey will become the default value for
that key (i.e. the value with name ""):

  >>> HKCU.Software.MyTests = "dead parrot"
  >>> HKCU.Software.MyTests[""].data
  u'dead parrot'



I could see how you could map  numbers to DWORD, 2.x str/3.x bytes to 
binary, and 2.x unicode/3.x str to REG_SZ.  But you don't document such 
a translation, so it is unclear exactly what you actually do.  This 
would be somewhat weird in 2.x, though, where str commonly would want to 
map to String rather than Binary.


It seems almost necessary to add an explanation of whatever mapping is 
presently done, to have complete documentation.




Thinking more, I wonder if it is possible to create objects of type 
Value to put in the dictionary to allow specification of multistring and 
expandablestring Registry types, but then the dictionary name would have 
to be redundant with the name attribute in the Value object.  Maybe a 
nameless value type could be invented, with just type and data attributes?


Then the dictionary could be populated with numbers (mapped to DWORD) 
str or unicode items (mapped to String), [3.x only] bytes (mapped to 
Binary), or nameless value objects (which map to their internal types).




This would allow a bidirectional conversion between dictionaries and 
registry keys... when asking for the value of a key, one could return a 
dictionary of nameless value types... and allow iterations over that.


Subkeys could be a tuple with the type of key, and the value of a key 
object.



Well, these are just thoughts.  I don't know if they would increase or 
decrease the Pythonicity of your design, which certainly sounds better 
than using _winreg, to me.



--
Glenn -- http://nevcal.com/
===
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking
--
http://mail.python.org/mailman/listinfo/python-list


Re: free chart lib for Python?

2009-05-08 Thread Glenn Hutchings
On Fri, 08 May 2009 10:27:08 +0800, oyster wrote:

> I mean chart, not plot. If you don't know the difference, you can
> check www.advsofteng.com, which is a commercial program
> 
> is there such a thing with many kinds of chart, i.e. pie-chart,
> line-chart, ..?

You could try matplotlib: http://matplotlib.sourceforge.net.  That can do
all kinds of wizzo plotty/charty stuff.
--
http://mail.python.org/mailman/listinfo/python-list


Re: import overwrites __name__

2009-05-08 Thread Glenn Hutchings
On Fri, 08 May 2009 19:14:52 +0200, Marco wrote:

> I import a module and then the name space of the importing module seems do 
> be overwritten.
> 
> my_name = __name__
> print my_name
> print len(dir())
> from x import y as z
> print __name__
> print len(dir())
> print my_name
> 
> ->
> __main__
> 119
> x
> 117
> unhandled NameError "name 'my_name' is not defined"

Interesting.  Here's one possibility for the contents of module x.py:

import sys
del sys.modules['__main__'].my_name
y = 42

I can't think of any other way apart from grovelling through sys.modules.

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


Re: Graphics

2008-07-11 Thread Glenn Hutchings
vanam <[EMAIL PROTECTED]> writes:

> hi all
> i am new to python programming a beginner. I Came to know from the
> groups that "How to think like a computer scientist" is preferable for
> begineers. i just looking through that i came to one section where a
> sample program for generation of graphics is present.i tried to copy
> the same script to the interpreter and it is showing an error i want
> to know whether is there anything that has to be installed in addition
> to python 2.5
> below is the program
> from gasp import *
> begin_graphics()
> Circle((200, 200), 60)
> Line((100, 400), (580, 200))
> Box((400, 350), 120, 100)
> end_graphics()

You're probably getting an ImportError from the 'from gasp...' line.  You
need to grab and install the GASP package from https://launchpad.net/gasp.

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


[ANN] PyStar 0.1 -- A* graph search algorithm

2008-07-18 Thread Glenn Hutchings
Announcing PyStar, a python module implementing the A* graph search
algorithm.  Available under the GPL, you can find it at

http://fluffybunny.memebot.com/pystar.html

I tried to find a decent Python version of this on the Interweb, but the
only one I found (http://arainyday.se/projects/python/AStar) was just a bit
too cryptic for me to understand and use.  So I knocked this up from
pseudocode on the Wikipedia A* page, and rewrote the AStar demo program in
Tkinter.

Comments, bug reports, big wads of cash, etc., are welcome.
--
http://mail.python.org/mailman/listinfo/python-list


Re: calling source command within python

2008-07-25 Thread Glenn Hutchings
Jie <[EMAIL PROTECTED]> writes:
> i'm having trouble executing os.system('source .bashrc') command
> within python, it always says that source not found and stuff. Any
> clue?

There's no 'source' program; it's a shell builtin.  Even if there was, it
almost certainly wouldn't do what you want.  The .bashrc file is supposed
to contain settings applying to the current shell, and os.system() runs in
a subshell, so the settings will only affect that shell.

If you're doing this to set environment variables, try modifying os.environ
instead.

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


Re: Are rank noobs tolerated, here?

2008-05-04 Thread Glenn Hutchings
notbob <[EMAIL PROTECTED]> writes:
> Am I likely to receive any help, here, or is there another irc, forum, etc,
> that might better serve a complete amateur such as myself.  Thnx.

You're very likely to receive help here.  Or at the very least, people will
point you at the best place to get it.  Fire away!

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


Re: Numpy not found

2008-05-04 Thread Glenn Hutchings
adolfo <[EMAIL PROTECTED]> writes:

> I downloaded and installed Phyton 2.52 (it works), numpy-1.0.4.win32-
> py2.5, and scipy-0.6.0.win32-py2.5
>
> I can´t get Numpy to show up at Python´s  IDLE, or command line. If I
> do:
>
>>>>> import Numeric
> # I get
>>>>> Traceback (most recent call last):
>   File "", line 1, in 
> import Numeric
> ImportError: No module named Numeric

Try 'import numpy' instead.  Numeric is an earlier incarnation of numpy --
it has (mostly) the same interface, but is a different package.  (Just to
confuse things even further, there's also another old one, called
numarray).

> And if I do:
>>>>> import Numeric *
> # I get
> SyntaxError: invalid syntax

The proper syntax for that is (assuming you want numpy instead) 'from numpy
import *'.

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


Re: When to use try and except?

2008-08-29 Thread Glenn Hutchings
cnb <[EMAIL PROTECTED]> writes:

> A ZeroDivisionError is better avoided wth an if-clause, don't you
> think? It is a predictable exception...

It depends.  If zero-division is unlikely, then things would probably[*]
run faster without checking.  If speed is what you're interested in, that
is...

Glenn

[*] Haven't checked, so don't really know :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Process "Killed"

2008-08-29 Thread Glenn Hutchings
dieter <[EMAIL PROTECTED]> writes:

> I'm doing some simple file manipulation work and the process gets
> "Killed" everytime I run it. No traceback, no segfault... just the
> word "Killed" in the bash shell and the process ends. The first few
> batch runs would only succeed with one or two files being processed
> (out of 60) before the process was "Killed". Now it makes no
> successful progress at all. Just a little processing then "Killed".
>
> Any Ideas? Is there a buffer limitation? Do you think it could be the
> filesystem?
> Any suggestions appreciated Thanks.
>
> The code I'm running:
> ==
>
> from glob import glob
>
> def manipFiles():
> filePathList = glob('/data/ascii/*.dat')
> for filePath in filePathList:
> f = open(filePath, 'r')
> lines = f.readlines()[2:]
> f.close()
> f = open(filePath, 'w')
> f.writelines(lines)
> f.close()
> print file

Have you checked memory usage while your program is running?  Your

lines = f.readlines()[2:]

statement will need almost twice the memory of your largest file.  This
might be a problem, depending on your RAM and what else is running at the
same time.

If you want to reduce memory usage to almost zero, try reading lines from
the file and writing all but the first two to a temporary file, then
renaming the temp file to the original:

import os

infile = open(filePath, 'r')
outfile = open(filePath + '.bak', 'w')

for num, line in enumerate(infile):
if num >= 2:
outfile.write(line)

infile.close()
outfile.close()
os.rename(filePath + '.bak', filePath)

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


Re: Query about doing fortran-esque repeat formatting

2009-11-09 Thread Glenn Hutchings
Rob Briggs  mun.ca> writes:

> Is there a way to do a repeat formatting command like in Fortran? Rather
> that doing this:
> 
> print "%s %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f %-5.3f" %
> (parmName[i], tmp[i][1], tmp[i][2], tmp[i][4],  tmp[i][6],  tmp[i][7],
> tmp[i][8],  tmp[i][9])

There certainly is.  You can use python's string concatenation
and repeat operators:

print "%s" + " %-5.3f" * 7 % 

Glenn

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


ZipFile - file adding API incomplete?

2009-11-16 Thread Glenn Maynard
I want to do something fairly simple: read files from one ZIP and add
them to another, so I can remove and replace files.  This led me to a
couple things that seem to be missing from the API.

The simple approach would be to open each file in the source ZIP, and
hand it off to newzip.write().  There's a missing piece, though:
there's no API that lets me pass in a file-like object and a ZipInfo,
to preserve metadata.  zip.write() only takes the filename and
compression method, not a ZipInfo; writestr takes a ZipInfo but only
accepts a string, not a file.  Is there an API call I'm missing?
(This seems like the fundamental API for adding files, that write and
writestr should be calling.)

The correct approach is to copy the data directly, so it's not
recompressed.  This would need two new API calls: rawopen(), acting
like open() but returning a direct file slice and not decompressing
data; and rawwrite(zinfo, file), to pass in pre-compressed data, where
the compression method in zinfo matches the compression type used.

I was surprised that I couldn't find the former.  The latter is an
advanced one, important for implementing any tool that modifies large
ZIPs.  Short-term, at least, I'll probably implement these externally.

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


  1   2   >