Re: LANG, locale, unicode, setup.py and Debian packaging

2008-01-12 Thread Donn
Martin,
I really appreciate your reply. I have been working in a vacuum on this and 
without any experience. I hope you don't mind if I ask you a bunch of 
questions. If I can get over some conceptual 'humps' then I'm sure I can 
produce a better app.

> That's a bug in the app. It shouldn't assume that environment variables
> are UTF-8. Instead, it should assume that they are in the locale's
> encoding, and compute that encoding with locale.getpreferredencoding.
I see what you are saying and agree, and I am confused about files and 
filenames. My app has to handle font files which can come from anywhere. If 
the locale (locale.getpreferredencoding) returns something like "ANSI" and I 
am doing an os.listdir() then I lose the plot a little...

 It seems to me that filenames are like snapshots of the locales where they 
originated. If there's a font file from India and I want to open it on my 
system in South Africa (and I have LANG=C) then it seems that it's impossible 
to do. If I access the filename it throws a unicodeDecodeError. If I 
use 'replace' or 'ignore' then I am mangling the filename and I won't be able 
to open it.

 The same goes for adding 'foreign' filenames to paths with any kind of string 
operation. 

 My (admittedly uninformed) conception is that by forcing the app to always 
use utf8 I can access any filename in any encoding. The problem seems to be 
that I cannot know *what* encoding (and I get encode/decode mixed up still, 
very new to it all) that particular filename is in.

Am I right? Wrong? Deluded? :) Please fill me in.

> If you print non-ASCII strings to the terminal, and you can't be certain
> that the terminal supports the encoding in the string, and you can't
> reasonably deal with the exceptions, you should accept moji-bake, by
> specifying the "replace" error handler when converting strings to the
> terminal's encoding.
I went through this exercise recently and had no joy. It seems the string I 
chose to use simply would not render - even under 'ignore' and 'replace'. 
It's really frustrating because I don't speak a non-ascii language and so 
can't know if I am testing real-world strings or crazy Tolkein strings.

Another aspect of this is wxPython. My app requires the unicode build so that 
strings have some hope of displaying on the widgets. If I access a font file 
and fetch the family name - that can be encoded in any way, again unknown, 
and I want to fetch it as 'unicode' and pass it to the widgets and not worry 
about what's really going on. Given that, I thought I'd extend the 'utf8' 
only concept to the app in general. I am sure I am wrong, but I feel cornered 
at the moment.

> > 3. I made the decision to check the locale and stop the app if the return
> > from getlocale is (None,None).
> I would avoid locale.getlocale. It's a pointless function (IMO).
Could you say why?

Here's my use of it:
locale.setlocale( locale.LC_ALL, "" )
loc = locale.getlocale()[0]
if loc == None:
loc = locale.getlocale()
if loc == (None, None):
print localeHelp   # not utf-8 (I think)
raise SystemExit
# Now gettext
domain = "all"
gettext.install( domain, localedir, unicode = True )
lang = gettext.translation(domain, localedir, languages = [loc] )
lang.install(unicode = True )

So, I am using getlocale to get a tuple/list (easy, no?) to pass to the 
gettext.install function.

> Your program definitely, absolutely must work in the C locale. Of
> course, you cannot have any non-ASCII characters in that locale, so
> deal with it.
This would mean cutting-out a percentage of the external font files that can 
be used by the app. Is there no modern standard regarding the LANG variable 
and locales these days? My locale -a reports a bunch of xx_XX.utf8 locales. 
Does it even make sense to use a non-utf8 locale anymore?

> If you have solved that, chances are high that it will work in other
> locales as well (but be sure to try Turkish, as that gives a
> surprising meaning to "I".lower()).
Oh boy, this gives me cold chills. I don't have the resources to start 
worrying about every single language's edge-cases. This is kind of why I was 
leaning towards a "use a utf8 locale please" approach.


\d

-- 
Fonty Python and other dev news at:
http://otherwiseingle.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Elementary string-formatting

2008-01-12 Thread Roberto Bonvallet
On Jan 12, 10:15 pm, Odysseus <[EMAIL PROTECTED]> wrote:
> P.S. Is there a preferable technique for forcing floating-point division
> of two integers to that used above, multiplying by "100.0" first?

Put this at the beginning of your program:

from __future__ import division

This forces all divisions to yield floating points values:

>>> 1/3
0
>>> from __future__ import division
>>> 1/3
0.1
>>>

HTH,
--
Roberto Bonvallet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Elementary string-formatting

2008-01-12 Thread John Machin
On Jan 13, 3:15 pm, Odysseus <[EMAIL PROTECTED]> wrote:
[snip]
>
> P.S. Is there a preferable technique for forcing floating-point division
> of two integers to that used above, multiplying by "100.0" first? What
> about if I just wanted a ratio: is "float(n / m)" better than "1.0 * n /
> m"?

> Odysseus

You obviously haven't tried float(n / m), or you wouldn't be asking.
Go ahead and try it.

"Preferable" depends on whether you want legibility or speed.

Most legible and slowest first:
1. float(n) / float(m)
2. n / float(m)
3. 1.0 * n / m
# Rationale so far: function calls are slow
4. If you have a lot of this to do, and you really care about the
speed and m (the denominator) is constant throughout, do fm = float(m)
once, and then in your loop do n / fm for each n -- and make sure you
run properly constructed benchmarks ...

Recommendation: go with (2) until you find you've got a program with
a real speed problem (and then it probably won't be caused by this
choice).

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


OSCON 2008 Call for Proposals

2008-01-12 Thread Aahz
The O'Reilly Open Source Convention (OSCON) is accepting proposals for
tutorials and presentations.  The submission period ends Feb 4.

OSCON 2008 will be in Portland, Oregon July 21-25.  For more information
and to submit a proposal, see

http://conferences.oreilly.com/oscon/
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Elementary string-formatting

2008-01-12 Thread Gary Herron
Odysseus wrote:
> Hello, group: I've just begun some introductory tutorials in Python. 
> Taking off from the "word play" exercise at
>
> 
>
> I've written a mini-program to tabulate the number of characters in each 
> word in a file. Once the data have been collected in a list, the output 
> is produced by a while loop that steps through it by incrementing an 
> index "i", saying
>
> print '%2u %6u %4.2f' % \
> (i, wordcounts[i], 100.0 * wordcounts[i] / wordcounts[0])
>   
Using 4.2 is the problem.  The first digit (your 4) give the total
number of characters to use for the number.  Your numbers require at
least 5 characters, two digits,  one decimal point, and two more
digits.  So try 5.2, or 6.2 or 7.2 or higher if your numbers can grow
into the hundreds or thousands or higher.  If you want to try one of the
floating point formats, then your first number must be large enough to
account for digits (before and after) the decimal point, the 'E', and
any digits in the exponent, as well as signs for both the number and the
exponent.

Gary Herron

> My problem is with the last entry in each line, which isn't getting 
> padded:
>
>  1  0 0.00
>  2 85 0.07
>  3908 0.80
>  4   3686 3.24
>  5   8258 7.26
>  6  14374 12.63
>  7  21727 19.09
>  8  26447 23.24
>  9  16658 14.64
> 10   9199 8.08
> 11   5296 4.65
> 12   3166 2.78
> 13   1960 1.72
> 14   1023 0.90
> 15557 0.49
> 16261 0.23
> 17132 0.12
> 18 48 0.04
> 19 16 0.01
> 20  5 0.00
> 21  3 0.00
>
> I've tried varying the number before the decimal in the formatting 
> string; "F", "g", and "G" conversions instead of "f"; and a couple of 
> other permutations (including replacing the arithmetical expression in 
> the tuple with a variable, defined on the previous line), but I can't 
> seem to get the decimal points to line up. I'm sure I'm missing 
> something obvious, but I'd appreciate a tip -- thanks in advance!
>
> FWIW I'm running
>
> Python 2.3.5 (#1, Oct  5 2005, 11:07:27) 
> [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin
>
> from the Terminal on Mac OS X v10.4.11.
>
> P.S. Is there a preferable technique for forcing floating-point division 
> of two integers to that used above, multiplying by "100.0" first? What 
> about if I just wanted a ratio: is "float(n / m)" better than "1.0 * n / 
> m"?
>
>   

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


Elementary string-formatting

2008-01-12 Thread Odysseus
Hello, group: I've just begun some introductory tutorials in Python. 
Taking off from the "word play" exercise at



I've written a mini-program to tabulate the number of characters in each 
word in a file. Once the data have been collected in a list, the output 
is produced by a while loop that steps through it by incrementing an 
index "i", saying

print '%2u %6u %4.2f' % \
(i, wordcounts[i], 100.0 * wordcounts[i] / wordcounts[0])

My problem is with the last entry in each line, which isn't getting 
padded:

 1  0 0.00
 2 85 0.07
 3908 0.80
 4   3686 3.24
 5   8258 7.26
 6  14374 12.63
 7  21727 19.09
 8  26447 23.24
 9  16658 14.64
10   9199 8.08
11   5296 4.65
12   3166 2.78
13   1960 1.72
14   1023 0.90
15557 0.49
16261 0.23
17132 0.12
18 48 0.04
19 16 0.01
20  5 0.00
21  3 0.00

I've tried varying the number before the decimal in the formatting 
string; "F", "g", and "G" conversions instead of "f"; and a couple of 
other permutations (including replacing the arithmetical expression in 
the tuple with a variable, defined on the previous line), but I can't 
seem to get the decimal points to line up. I'm sure I'm missing 
something obvious, but I'd appreciate a tip -- thanks in advance!

FWIW I'm running

Python 2.3.5 (#1, Oct  5 2005, 11:07:27) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin

from the Terminal on Mac OS X v10.4.11.

P.S. Is there a preferable technique for forcing floating-point division 
of two integers to that used above, multiplying by "100.0" first? What 
about if I just wanted a ratio: is "float(n / m)" better than "1.0 * n / 
m"?

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


Re: Why my program (using pexpect to switch user) doesn't work well?

2008-01-12 Thread BlackjadeLin
On Jan 11, 1:49 am, Noah <[EMAIL PROTECTED]> wrote:
> On Jan 10, 12:59 am, BlackjadeLin <[EMAIL PROTECTED]> wrote:
>
>
>
> > I'm new to python
> > I want to write a simple script to switch user,for example,from user_A
> > to user_B.
> > This my codes:
>
> > #!/usr/bin/python
> > importpexpect
> > import os
> > passwd="user_B"
> > child =pexpect.spawn('su user_B')
> > child.expect('Password:')
> > child.sendline(passwd)
> > child.expect('$')
> > child.close()
>
> > Maybe it's the easiest pexpect program.Sometimes ,it work well,it
> > switch to user_B successfully .But after i type the command exit to
> > switch back to user_A,execute the python script again,it can't work,do
> > nothing or just waiting.Why it have different results?
> > Sorry for my poor English,and many thanks to all.
>
> > Blackjade
>
> When you call child.close() that will kill the child process.
> Possibly you want to use the interact() method.
> It is not clear from your message if you want to interact with
> the child process as if it were your new shell. If you do,
> then take a look at the interact() method.
>
>   #!/usr/bin/python
>   importpexpect
>   import os
>   passwd="user_B"
>   child =pexpect.spawn('su user_B')
>   child.expect('Password:')
>   child.sendline(passwd)
>   child.expect('$')
>   child.interact()
>
> --
> Noah

Thank you very much!
The  interact() method complete my achievement.
-- 
http://mail.python.org/mailman/listinfo/python-list


pygtk dnd woes

2008-01-12 Thread [EMAIL PROTECTED]

Hi all,

DND has just about got me going bonkers.
I want to process the dnd drop to main window and then process the 
dnd_list to ship to open_arg. Resulting in individual editor panes 
opening the files.

The problem:
TypeError: dnd_drop() takes exactly 6 arguments (8 given) or
TypeError: dnd_drop() takes exactly 8 arguments (6 given)

Seems I'm in a catch 22 here.  The code:

  # read notes
  self.on_read_notes()
  # dnd 
#
  self.TARGET_TYPE_URI_LIST = 80
  self.window.dnd_list = [ ( 'text/plain', 0, self.TARGET_TYPE_URI_LIST ) ]
  self.window.drag_dest_set(gtk.DEST_DEFAULT_MOTION | 
gtk.DEST_DEFAULT_HIGHLIGHT,
   self.window.dnd_list, gtk.gdk.ACTION_COPY)
  self.window.connect('drag_data_received', self.dnd_drop)
  self.window.drag_dest_set(gtk.DEST_DEFAULT_ALL,
[ ( 'text/uri-list', 0, self.TARGET_TYPE_URI_LIST ) ],
gtk.gdk.ACTION_COPY)
  self.window.connect('drag_drop', self.dnd_drop)
#
  # show all
  self.window.show_all()
  self.window.set_title('GEd:')
  self.window.show()
  # welcome
  self.set_status('Welcome to GEd-V-0.1 :-) ...') 
#
   #--  

   def dnd_drop(self, widget, context, x, y, times):
#(self, widget, context, x, y, selection, target_type, 
time):
# process list and and ship to open_arg
print 'data received'
context.finish(True, False, time)
return True
# 
   #--
   def on_blank(self, widget):
  pass  

Thanks
john




___
Join Excite! - http://www.excite.com
The most personalized portal on the Web!


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


Re: Great Python books for the beginner

2008-01-12 Thread Dick Moores
At 11:03 PM 1/11/2008, Landon wrote:
>Hi, I'm a freshman in college and I'm going to be taking an intro to
>programming course next semester which mainly uses Python, so I
>thought it might be a good time to pick up Python beyond the scope of
>the class as well. The text book for this class is Python for the
>Absolute Beginner or something similar to that name.
>
>I was wondering if anyone had any opinions on what other titles I
>could look into since this one seems from a glance at reviews to be
>teaching mainly through game programming (a topic I'm not too
>interested in) or if this one is a quality book by itself.

Yes, it's a quality book, IMO.

I hope by now you've gotten over your dislike for online tutorials. 
Please take a look at these 3:
Hands-On Python 
How to Think Like a (Python) Programmer 

Alan Gauld's Learning to Program (heavy emphasis on Python) 


Also, do take advantage of the VERY helpful Tutor mailing list. 
.

Dick Moores

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

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


Re: DEK's birthday

2008-01-12 Thread George Neuner
On Sat, 12 Jan 2008 12:03:49 -0800 (PST), [EMAIL PROTECTED] wrote:

>On Jan 10, 9:57 am, Jim <[EMAIL PROTECTED]> wrote:
>> DEK celebrates 70 today.
>>
>> I doubt he'll read this but I'll say it anyway: Happy Birthday!
>>
>> Jim Hefferon
>
>Donald Knuth is a son of a bitch who made a lot of money from tax
>payer's grants. The computers he began with were built with tax
>payer's money.
>
>His mother lived in the same newyork where the yank bastards staged
>that fake drama
>
>letsroll911.org
>stj911.org
>scholarsfor911truth.org
>nkusa.org
>countercurrents.org
>counterpunch.org
>
>and the bastard did not lift a finger, did not lift a pen in the
>defense of the truth.
>
>may such bastard scholars burn in hell for ever and never know the
>kingdom of heavan.
>
>Amen


Why don't you play Hide And Go Fuck Yourself.

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


Re: Is unicode.lower() locale-independent?

2008-01-12 Thread Robert Kern
Martin v. Löwis wrote:
>> Even if towlower() gets used? I've found an explicit statement that the
>> conversion it does can be locale-specific:
>>
>>   http://msdn2.microsoft.com/en-us/library/8h19t214.aspx
> 
> Right. However, the build option of Python where that's the case is
> deprecated.

Excellent. Thank you.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

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

Re: Is unicode.lower() locale-independent?

2008-01-12 Thread John Machin
On Jan 13, 9:49 am, Carl Banks <[EMAIL PROTECTED]> wrote:
> On Sat, 12 Jan 2008 13:51:18 -0800, John Machin wrote:
> > On Jan 12, 11:26 pm, Torsten Bronger <[EMAIL PROTECTED]>
> > wrote:
> >> Hallöchen!
>
> >> Fredrik Lundh writes:
> >> > Robert Kern wrote:
>
> >> >>> However it appears from your bug ticket that you have a much
> >> >>> narrower problem (case-shifting a small known list of English words
> >> >>> like VOID) and can work around it by writing your own
> >> >>> locale-independent casing functions. Do you still need to find out
> >> >>> whether Python unicode casings are locale-dependent?
>
> >> >> I would still like to know. There are other places where .lower() is
> >> >> used in numpy, not to mention the rest of my code.
>
> >> > "lower" uses the informative case mappings provided by the Unicode
> >> > character database; see
>
> >> >http://www.unicode.org/Public/4.1.0/ucd/UCD.html
>
> >> > afaik, changing the locale has no influence whatsoever on Python's
> >> > Unicode subsystem.
>
> >> Slightly off-topic because it's not part of the Unicode subsystem, but
> >> I was once irritated that the none-breaking space (codepoint xa0 I
> >> think) was included into string.whitespace.  I cannot reproduce it on
> >> my current system anymore, but I was pretty sure it occured with a
> >> fr_FR.UTF-8 locale.  Is this possible?  And who is to blame, or must my
> >> program cope with such things?
>
> > The NO-BREAK SPACE is treated as whitespace in the Python unicode
> > subsystem. As for str objects, the default "C" locale doesn't know it
> > exists; otherwise AFAIK if the character set for the locale has it, it
> > will be treated as whitespace.
>
> > You were irritated because non-break SPACE was included in
> > string.whiteSPACE? Surely not! It seems eminently logical to me.
>
> To me it seems the point of a non-breaking space is to have something
> that's printed as whitespace but not treated as it.

To me it seems the point of a no-break space is that it's treated as a
space in all respects except that it doesn't "break".

>
> > Perhaps
> > you were irritated because str.split() ignored the "no-break"? If like
> > me you had been faced with removing trailing spaces from text columns in
> > databases, you surely would have been delighted that str.rstrip()
> > removed the trailing-padding-for-nicer-layout no-break spaces that the
> > users had copy/pasted from some clown's website :-)
>
> > What was the *real* cause of your irritation?
>
> If you want to use str.split() to split words, you will foil the user who
> wants to not break at a certain point.

Which was exactly my point -- but this would happen only rarely or not
at all in my universe (names, addresses, product descriptions, etc in
databases).

>
> Your use of rstrip() is a lot more specialized, if you ask me.

Not very specialised at all in my universe -- a standard
transformation that one normally applies to database text is to remove
all leading and trailing whitespace, and compress runs of 1 or more
whitespace characters to a single normal space. Your comment seems to
imply that trailing non-break spaces are significant and should be
preserved ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is unicode.lower() locale-independent?

2008-01-12 Thread John Machin
On Jan 13, 10:31 am, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> > The Unicode standard says that case mappings are language-dependent.
>
> I think you are misreading it.

Ummm well, it does say "normative" as opposed to Fredrik's
"informative" ...

> 5.18 "Implementation Guides" says
> (talking about "most environments") "In such cases, the
> language-specific mappings *must not* be used." (emphasis also
> in the original spec).
>

Here is the paragraph from which you quote:
"""
In most environments, such as in file systems, text is not and cannot
be tagged with language information. In such cases, the language-
specific mappings /must not/ be used. Otherwise, data structures such
as B-trees might be built based on one set of case foldings and used
based on a different set of case foldings. This discrepancy would
cause those data structures to become corrupt. For such environments,
a constant, language-independent, default case folding is required.
"""
This is from the middle of a section titled "Caseless Matching"; this
section starts:
"""
Caseless matching is implemented using case folding, which is the
process of mapping strings to a canonical form where case differences
are erased. Case folding allows for fast
caseless matches in lookups because only binary comparison is
required. It is more than just conversion to lowercase. For example,
it correctly handles cases such as the Greek sigma, so that
 and  will
match.
"""

Python doesn't offer a foldedcase method, and the attitude of 99% of
users would be YAGNI; use this:
foldedcase = lambda x: x.lower()

What the paragraph you quoted seems to be warning about is that people
who do implement a fully-principled foldedcase using the Unicode
CaseFolding.txt file should be careful about offering foldedcaseTurkic
and foldedcaseLithuanianDictionary -- both dangerous and YAGNI**2.

This topic seems to be quite different to the topic of whether the
results of unicode.lower does/should depend on the locale or not.


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


Re: __init__ explanation please

2008-01-12 Thread Colin J. Williams
Erik Lind wrote:
> I'm new to Python, and OOP. I've read most of Mark Lutz's book and more 
> online and can write simple modules, but I still don't get when __init__ 
> needs to be used as opposed to creating a class instance by assignment. For 
> some strange reason the literature seems to take this for granted. I'd 
> appreciate any pointers or links that can help clarify this.
> 
> Thanks
> 
> 
You don't always need __init__ if 
__new__ is used with a "new" class.

Colin W.

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


Re: __init__ explanation please

2008-01-12 Thread Daniel Fetchinson
> I'm new to Python, and OOP. I've read most of Mark Lutz's book and more
> online and can write simple modules, but I still don't get when __init__
> needs to be used as opposed to creating a class instance by assignment. For
> some strange reason the literature seems to take this for granted. I'd
> appreciate any pointers or links that can help clarify this.

I'm not sure if I understand your question correctly but maybe this will help:

If you want code to be run upon creating an instance of your class you
would use __init__. Most common examples include setting attributes on
the instance and doing some checks, e.g.

class Person:
def __init__( self, first, last ):
if len( first ) > 50 or len( last ) > 50:
raise Exception( 'The names are too long.' )
self.first = first
self.last = last

And you would use your class like so,

p1 = Person( 'John', 'Smith' )
p2 = Person( "Some long fake name that you don't really want to
except, I don't know if it's really longer than 50 but let's assume it
is", "Smith" )
# This last one would raise an exception so you know that something is not okay

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


Re: executing newgrp from python in current shell possible?

2008-01-12 Thread Karthik Gurusamy
On Jan 12, 6:19 am, Svenn Are Bjerkem <[EMAIL PROTECTED]>
wrote:
> On Jan 9, 9:18 pm, Zentrader <[EMAIL PROTECTED]> wrote:
>
> > On Jan 9, 5:56 am, Svenn Are Bjerkem <[EMAIL PROTECTED]>
> > wrote:
>
> > >I have been looking for a way to execute this command
> > > as a part of a script, but it seems that the changes are only valid in
> > > the context of the script and when the script exits, the current shell
> > > still have the original "users" group setting.
>
> > I don't think you would want it any other way.  Would you want a user
> > to be able to change the group and have it remain permanently?  Who's
> > going to remember whether they were last in "A" or "B", and it opens
> > up oportunities for the practical joker when you go to the restroom
> > and leave the terminal on.  Put the "change the group" code into a
> > separate function in a separate file (with only you as the owner) and
> > call it whenever you want to change groups.
>
> I am trying to create a script that make it easy for users in a design
> team to create files that belong to the same group, but retain the
> users uid. In order to make it visible that the user is creating files
> with a different gid, the script will change the prompt to indicate
> so. In a tcl solution I have now, the users home is changed to the
> design area as some tools are reading and writing setup files into
> $HOME. I have not found a way to change the gid in tcl so I turned to
> python in hope that this scripting language could do so.
>
> The tcl solution spawns a new tcsh after setting several environment
> variables and works quite well except for not being able to change
> gid. And it is also a wish from my side to port this script to python.
>
> Is your suggestion to put "newgrp design" into a new file and then
> exec this file in my python script? What happens to the group id of
> the shell that called the python script in this case? I would try to
> avoid spawning a new tcsh as this make execution of tools on a remote
> computer difficult as the handover of command line arguments does not
> seem to be handed over to the newly spawned shell. I may be
> understanding something wrongly here.

When you fork a process in unix/linux, the child inherits all of
parents settings; *but* any future changes that is made in child
process will not get reflected in the parent.

So there is no way you can fire a process and some how get its setting
back to the invoking shell (which could be anything btw, say bash/tcsh/
csh).

Thus what you really want is start a wrapper python script, say
setup_design.py
In setup_design.py, call necessary os routines like  setegid(egid);
this will update the process settings of the process running
setup_design.py.

At the end of setup_design.py, do an exec call[1] to fire the user's
shell (note that even if you use popen or other ways of forking a new
process, things will work just fine) Whatever changes you made to the
process environment will get propagated to the new shell. User must
explicitly finish the new shell (say typing 'exit' on shell prompt)

Karthik

[1]. e.g.
import os
os.execvp(cmd_run[0], cmd_run)   # cmd_run is probably ['/bin/bash']


>
> --
> Svenn

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


__init__ explanation please

2008-01-12 Thread Erik Lind
I'm new to Python, and OOP. I've read most of Mark Lutz's book and more 
online and can write simple modules, but I still don't get when __init__ 
needs to be used as opposed to creating a class instance by assignment. For 
some strange reason the literature seems to take this for granted. I'd 
appreciate any pointers or links that can help clarify this.

Thanks


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


Re: *** American nationalism is FAKE and its MYTHS are LIES, YANK BASTARDS RAPED BY THEIR OWN MARINES - ***

2008-01-12 Thread PeterD
On Sat, 12 Jan 2008 11:50:07 -0800 (PST), [EMAIL PROTECTED] wrote:

>THE YANK CHRISTIAN WHITE MARINE 

Recently in Chicago an Indian father killed his daughter, and and her
two children... Why? Because she'd married without his permission. So
that seems to make your and your countrymen so many steps below
Americans that this becomes the stupidest thread of the year...
Fortunately there are still 11 months to go for you to come wup with
something better. 

Peter's Troll-o-Meter

Not TrollTroll  
0 1 2 3 4 5 6 7 8 9 10
   /
  /
 /
/
   /
  /
 /
O

(Pegged the needle!)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is unicode.lower() locale-independent?

2008-01-12 Thread Torsten Bronger
Hallöchen!

John Machin writes:

> On Jan 12, 11:26 pm, Torsten Bronger <[EMAIL PROTECTED]>
> wrote:
>
>> [...]
>>
>> Slightly off-topic because it's not part of the Unicode
>> subsystem, but I was once irritated that the none-breaking space
>> (codepoint xa0 I think) was included into string.whitespace.  I
>> cannot reproduce it on my current system anymore, but I was
>> pretty sure it occured with a fr_FR.UTF-8 locale.  Is this
>> possible?  And who is to blame, or must my program cope with such
>> things?
>
> The NO-BREAK SPACE is treated as whitespace in the Python unicode
> subsystem. As for str objects, the default "C" locale doesn't know
> it exists; otherwise AFAIK if the character set for the locale has
> it, it will be treated as whitespace.
>
> [...]
>
> What was the *real* cause of your irritation?

I was missing something like string.ascii_whitespace in the string
module.  There is string.ascii_lower after all, and the
documentation doesn't clearly say string.whitespace is
locale-dependent.

In contrast to lower/uppercase conversions, where often human
language is transformed, the use cases for whitespace handling are
mostly syntactic purposes.  And parsing something with
locale-dependent whitespace definitions is broken.

Thus, I had the choice: defining my own whitespace constant, or
forcing the 'C' locale.  I chose the latter because I'm not a big
fan of locales anyway.

On my current computer(s), all locales seem to have the same
definition of whitespace as the 'C' locale.  I've only seen that one
(broken, in my opinion) French locale which included the NBSP.  In
my opinion, this is a trap rather than anything useful.  Well, if I
indeed remember it correctly; this is why I asked above, "Is it
possible?".

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
   (See http://ime.webhop.org for further contact info.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: super, decorators and gettattribute

2008-01-12 Thread Steven D'Aprano
On Sat, 12 Jan 2008 15:47:05 -0500, Mike Meyer wrote:

> There's an apparently common bug here: you don't want to pass super
> self.__class__, but the class that the method is bound to.

Given an instance method, is it possible to easily determine what class 
it is defined in?

I thought the im_class attribute might do it, but it apparently just 
points to self.__class__.

>>> class Foo(object):
... def foo(self):
... pass
...
>>> class Bar(Foo):
... def bar(self):
... pass
... 
>>> Bar().bar.im_class  # expecting Bar

>>> Bar().foo.im_class  # hoping for Foo




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


Re: Is unicode.lower() locale-independent?

2008-01-12 Thread Martin v. Löwis
> Even if towlower() gets used? I've found an explicit statement that the
> conversion it does can be locale-specific:
> 
>   http://msdn2.microsoft.com/en-us/library/8h19t214.aspx

Right. However, the build option of Python where that's the case is
deprecated.

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


Re: Is unicode.lower() locale-independent?

2008-01-12 Thread Martin v. Löwis
> The Unicode standard says that case mappings are language-dependent.

I think you are misreading it. 5.18 "Implementation Guides" says
(talking about "most environments") "In such cases, the
language-specific mappings *must not* be used." (emphasis also
in the original spec).

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


Re: different encodings for unicode() and u''.encode(), bug?

2008-01-12 Thread Martin v. Löwis
> What I'd like to understand better is the "compatibility heirarchy" of
> known encodings, in the positive sense that if a string decodes
> successfully with encoding A, then it is also possible that it will
> encode with encodings B, C; and in the negative sense that is if a
> string fails to decode with encoding A, then for sure it will also
> fail to decode with encodings B, C. Any ideas if such an analysis of
> the relationships between encodings exists?

Most certainly. You'll have to learn a lot about many encodings though
to really understand the relationships.

Many encodings X are "ASCII supersets", in the sense that if you have
only characters in the ASCII set, the encoding of the string in ASCII
is the same as the encoding of the string in X. ISO-8859-X, ISO-2022-X,
koi8-x, and UTF-8 fall in this category.

Other encodings are "ASCII supersets" only in the sense that they
include all characters of ASCII, but encode them differently. EBCDIC
and UCS-2/4, UTF-16/32 fall in that category.

Some encodings are 7-bit, so that they decode as ASCII (producing
moji-bake if the input wasn't ASCII). ISO-2022-X is an example.

Some encodings are 8-bit, so that they can decode arbitrary bytes
(again producing moji-bake if the input wasn't that encoding).
ISO-8859-X are examples, as are some of the EBCDIC encodings, and
koi8-x. Also, things will successfully (but meaninglessly) decode
as UTF-16 if the number of bytes in the input is even (likewise
for UTF-32).

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


Re: LANG, locale, unicode, setup.py and Debian packaging

2008-01-12 Thread Martin v. Löwis
> 2. If this returns "C" or anything without 'utf8' in it, then things start
> to go downhill:
>  2a. The app assumes unicode objects internally. i.e. Whenever there is
> a "string  like this" in a var it's supposed to be unicode. Whenever
> something comes into the app (from a filename, a file's contents, the
> command-line) it's assumed to be a byte-string that I decode("utf8") on
> before placing it into my objects etc.

That's a bug in the app. It shouldn't assume that environment variables
are UTF-8. Instead, it should assume that they are in the locale's
encoding, and compute that encoding with locale.getpreferredencoding.

>  2b. Because of 2a and if the locale is not 'utf8 aware' (i.e. "C") I start
> getting all the old 'ascii' unicode decode errors. This happens at every
> string operation, at every print command and is almost impossible to fix.

If you print non-ASCII strings to the terminal, and you can't be certain
that the terminal supports the encoding in the string, and you can't
reasonably deal with the exceptions, you should accept moji-bake, by
specifying the "replace" error handler when converting strings to the
terminal's encoding.

> 3. I made the decision to check the locale and stop the app if the return
> from getlocale is (None,None). 

I would avoid locale.getlocale. It's a pointless function (IMO).

Also, what's the purpose of this test?

> Does anyone have some ideas? Is there a universal "proper" locale that we
> could set a system to *before* the Debian build stuff starts? What would
> that be - en_US.utf8?

Your program definitely, absolutely must work in the C locale. Of
course, you cannot have any non-ASCII characters in that locale, so
deal with it.

If you have solved that, chances are high that it will work in other
locales as well (but be sure to try Turkish, as that gives a
surprising meaning to "I".lower()).

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


Re: Simple List division problem

2008-01-12 Thread Dustan
On Jan 12, 2:25 pm, Paul Rubin  wrote:
> marcstuart <[EMAIL PROTECTED]> writes:
> > what I would like to get is 3 sublists
>
> > print z[0] = [1,2,3]
> > print z[2] = [4,5,6]
> > print z[3] = [7,8,9,10]
>
> Are you SURE you want that?  In almost every situation I've seen,
>
>  print z[0] = [1,2,3]
>  print z[2] = [4,5,6]
>  print z[3] = [7,8,9]
>  print z[4] = [10]
>
> is preferable.

Even more preferable is:

 print z[0] = [1,2,3]
 print z[1] = [4,5,6]
 print z[2] = [7,8,9]
 print z[3] = [10]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Kamaelia] TCPClient: How to sense connection failure?

2008-01-12 Thread Michael Sparks
Bjoern Schliessmann wrote:
> Hello,
> 
> I'm currently trying to implement a simulation program with Kamaelia
> and need a reliable TCP connection to a data server.

The behaviour you're seeing sounds odd (which is hopefully encouraging :-),
but it's not clear from the description whether its a bug in your code or
Kamaelia. One question I really have as a result is what version are you
using?

Current release version 0.5.0, the version on /trunk, or the bleeding edge
version on /branches/private_MPS_Scratch. (I'm using the latter to run my
greylisting server - as are a few others).

All that said though, looking at the differences between versions, I'm not
convinced they're large enough to show the problem you're seeing.

I'm not about to rule out a bug I don't know about though :-)

> From Twisted, I know that a method is called if the connection fails
> by whatever reason. I tried to get the same results with Kamaelia's
> TCPClient component. If I start up the component and try to connect
> to a closed TCP port it fails and sends a message out of the signal
> box, that's okay.

If you'd prefer more information in that message, please let me know.
(all components send out a message when they shutdown. For things that
send  data out as one of their primary actions send out a producerFinished
message)

> But if the connection attempt succeeds and, after some time, the
> server drops the connection with full TCP handshake (FIN, FIN+ACK,
> ACK), the component just hangs and does nothing. Is this by design,
> or could there be an error in my setup?

It sounds like an error in your setup... but I hate saying that. (Doesn't
tell me or you what it is, and doesn't help change things to discourage or
detect mistakes in usage)

When the server drops the connection in my setups, the client disconnects
cleanly when the server dies, with the client code looking like this:
  self.send(producerFinished(self,self.howDied), "signal")

Meaning you get a message telling you how the component shutdown as well as
the fact it shutdown. (If "howDied" is None, it's just a normal shutdown -
ie as a result of being told to shut down)

The function where this is managed is runClient in the class 
   Kamaelia.Internet.TCPClient.TCPClient
(fully qualified name)

The actual socket connections are handled by a class called
ConnectedSocketAdapter which manages all logic of checking for
errors, remote shutdown etc. That works the same for both servers
and clients so breakage in clients would show up as breakage in servers
as well, which would be particularly bad. 

> Also, how long does a TCPClient component live -- or how can/should
> I terminate it explicitly? I'm afraid that if I create
> a "ReconnectingTCPClient" component, it could eat up memory over
> long runtime with hanging TCPClients.

That shouldn't be an issue (I hate the word "should"), but you can do this
using a carousel component. (I ought to write that as an example of how to
use the Carousel component)

In the meantime - whilst I check to see if there's a bug I didn't know
about, the following 2 cookbook entries may be of use:
   * http://kamaelia.sourceforge.net/Cookbook/TCPSystems
   * http://kamaelia.sourceforge.net/Cookbook/Carousels - allows you to make
 something that exits reusable. It's a little awkward to get your head
 around, but is quite useful when you do. (I've heard of others using
 Carousel & TCPClient to make a reconnecting TCPClient in the past)

All that said, I'm not going to rule out a bug and look into it. (if you
have a simple example you find fails, please forward it to me :)

*thinks*

The following code may also be useful when debugging:

from Kamaelia.Chassis.Pipeline import Pipeline

class PeriodicWakeup(Axon.ThreadedComponent.threadedcomponent):
interval = 300
def main(self):
while 1:
time.sleep(self.interval)
self.send("tick", "outbox")

class WakeableIntrospector(Axon.Component.component):
def main(self):
while 1:
Q = [ q.name for q in self.scheduler.listAllThreads() ]
Q.sort()
print "*debug* THREADS"+ str(Q)
self.scheduler.debuggingon = False
yield 1
while not self.dataReady("inbox"):
self.pause()
yield 1
while self.dataReady("inbox"):
self.recv("inbox")

Pipeline(
PeriodicWakeup(),
WakeableIntrospector(),
).activate()

If you put this code somewhere before your "run" call, you'll get periodic
output to tell you what's running. When debugging manually I'd drop the
interval to 3-10 seconds or so. I use 300 for a server.

Now, off to see if I can reproduce your problem... :)

Regards,


Michael.
--
http://kamaelia.sourceforge.net/Home
http://yeoldclue.com/blog

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


Re: Is unicode.lower() locale-independent?

2008-01-12 Thread Carl Banks
On Sat, 12 Jan 2008 13:51:18 -0800, John Machin wrote:

> On Jan 12, 11:26 pm, Torsten Bronger <[EMAIL PROTECTED]>
> wrote:
>> Hallöchen!
>>
>>
>>
>> Fredrik Lundh writes:
>> > Robert Kern wrote:
>>
>> >>> However it appears from your bug ticket that you have a much
>> >>> narrower problem (case-shifting a small known list of English words
>> >>> like VOID) and can work around it by writing your own
>> >>> locale-independent casing functions. Do you still need to find out
>> >>> whether Python unicode casings are locale-dependent?
>>
>> >> I would still like to know. There are other places where .lower() is
>> >> used in numpy, not to mention the rest of my code.
>>
>> > "lower" uses the informative case mappings provided by the Unicode
>> > character database; see
>>
>> >http://www.unicode.org/Public/4.1.0/ucd/UCD.html
>>
>> > afaik, changing the locale has no influence whatsoever on Python's
>> > Unicode subsystem.
>>
>> Slightly off-topic because it's not part of the Unicode subsystem, but
>> I was once irritated that the none-breaking space (codepoint xa0 I
>> think) was included into string.whitespace.  I cannot reproduce it on
>> my current system anymore, but I was pretty sure it occured with a
>> fr_FR.UTF-8 locale.  Is this possible?  And who is to blame, or must my
>> program cope with such things?
> 
> The NO-BREAK SPACE is treated as whitespace in the Python unicode
> subsystem. As for str objects, the default "C" locale doesn't know it
> exists; otherwise AFAIK if the character set for the locale has it, it
> will be treated as whitespace.
> 
> You were irritated because non-break SPACE was included in
> string.whiteSPACE? Surely not! It seems eminently logical to me.

To me it seems the point of a non-breaking space is to have something 
that's printed as whitespace but not treated as it.

> Perhaps
> you were irritated because str.split() ignored the "no-break"? If like
> me you had been faced with removing trailing spaces from text columns in
> databases, you surely would have been delighted that str.rstrip()
> removed the trailing-padding-for-nicer-layout no-break spaces that the
> users had copy/pasted from some clown's website :-)
> 
> What was the *real* cause of your irritation?

If you want to use str.split() to split words, you will foil the user who 
wants to not break at a certain point.

Your use of rstrip() is a lot more specialized, if you ask me.


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

Re: removeall() in list

2008-01-12 Thread castironpi
On Jan 12, 1:28 pm, Paul Rubin  wrote:
> [EMAIL PROTECTED] writes:
> > Will you engage with me over e-mail to discuss the Locker
> > implementation I'm developing?  Aaron
>
> I really can't, sorry.  I'm finding it hard enough to follow over the
> newsgroup.  If you just have a single one of these lists, it's
> probably simplest to do what Frederik Lundh suggested.  The other
> stuff we've discussed is mostly about how to organize having a lot of
> them.

Highlight from the working solution:

def onfulfill( self, func, *args, **kwargs ):
'''decorator launches its function in separate thread
upon completion of func.  todo: cancel and reference
check.'''
locfunc= Ref()
def honorth():
result= self.op( func, *args, **kwargs )
locfunc.val( result )
def prefulfill( func ):
locfunc.val= func
th= threading.Thread( target= honorth )
th.start()
return prefulfill
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is unicode.lower() locale-independent?

2008-01-12 Thread Robert Kern
Fredrik Lundh wrote:
> Robert Kern wrote:
> 
>>> However it appears from your bug ticket that you have a much narrower
>>> problem (case-shifting a small known list of English words like VOID)
>>> and can work around it by writing your own locale-independent casing
>>> functions. Do you still need to find out whether Python unicode
>>> casings are locale-dependent?
>> I would still like to know. There are other places where .lower() is used in 
>> numpy, not to mention the rest of my code.
> 
> "lower" uses the informative case mappings provided by the Unicode 
> character database; see
> 
>  http://www.unicode.org/Public/4.1.0/ucd/UCD.html
> 
> afaik, changing the locale has no influence whatsoever on Python's 
> Unicode subsystem.

Even if towlower() gets used? I've found an explicit statement that the 
conversion it does can be locale-specific:

   http://msdn2.microsoft.com/en-us/library/8h19t214.aspx

Thanks, Fredrik.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

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


Re: Magic function

2008-01-12 Thread dg . google . groups
Thanks everyone for the comments.

I had previously thought about the possibility of the classes keeping
track of their instances. I guess this could probably be done quite
transparently with a decorator too (as we have many different types of
objects being collected together). The only issue is that this
approach forces you to use what are essentially global variables,
whereas the searching through the stack method allows you to use the
structure of the program to organise what objects each 'magic'
function sees. Is this a good idea or not? I'm not entirely sure. I
think that personally I would lean towards using this method of
classes keeping track of their instances. It's not entirely my
decision so I'll see what the others say about it.

Any comments on this possibility: classes could keep track of their
instances, and also keep track of which function or module the
instances were defined in. Then, the magic functions could pick out
objects defined in the same function or module rather than looking at
the stack. This would achieve a similar thing, but is there any great
advantage in doing it this way? My first thought is that you'd still
have to go digging around in the stack to do this, but just not as
much.

Also, does anyone know of any specific things I should be aware of in
taking this stack searching approach? I'm thinking of, for example,
any planned changes in the execution model of Python or the
inspect.stack() function in the next version of Python.

Paul,

"Your users are *scientists*, and you don't trust their intellectual
ability to learn a programming language as simple as Python?"

Well, it's not quite as simple as that. One thing is that we're not
going to be able to force people to use our package. We believe it's
going to be considerably better - particularly in terms of ease of use
and extensibility - than the existing alternatives, but one of the
factors that will affect how many people start using it is how simple
we can make it to do basic things that they'll be familiar with. Many
scientists are using Python now, but it's not yet quite well known
enough that we can just assume that people will know it, and having to
learn the details of a new programming language is a considerable
disincentive for someone thinking about switching to a new piece of
software (even if, as you say, Python is not the most difficult
language to learn). Although the difference between the two pieces of
hypothetical code I presented seems quite trivial to an experienced
programmer, I think that the clarity and simplicity of the version
that uses the magic functions might make a difference. The difference
between being able to define and run a model with 10 lines or 20-30
lines of code might, somewhat perversely, be a significant factor.
(The example I gave was simplified to illustrate what was going on,
but the actual situation is more like you have 5 or 6 different types
of object, each of which uses other types of object to initialise
themselves, so that the magic function approach really reduces the
length of the program considerably.)

So, there's an aspect of PR about our wanting to have something like
the magic functions, but it's not entirely about self promotion,
because we think that in the long term it will be better for the users
if they switch to using our package (or something like it). The reason
being that the alternatives available at the moment all use their own
custom made programming languages which have nothing like the power of
a well developed general purpose language like Python, and are much
more difficult to use and extend. One of them is a stack based
language of all things!

Carl,

"Even if you implement magic functions, don't get rid of the
straightforward "hard way"."

Absolutely not! A very good point. In fact, the magic functions don't
actually do any work themselves, they just create and call the 'hard
way' functions (which are still visible to the user). They're an
additional layer of abstraction which you can choose to use or not
use. And actually, there will be situations where there is no
alternative but to use the 'hard way'. We already learnt this lesson:
a couple of our magic functions were behaving differently and causing
some odd behaviour, so we changed them and now we're working on
building a more consistent and explicit interface (and enforcing it
works as expected with the unit testing module, a tedious but
hopefully very useful exercise in the long run).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *** American nationalism is FAKE and its MYTHS are LIES, YANK BASTARDS RAPED BY THEIR OWN MARINES - ***

2008-01-12 Thread Dan Upton
On Jan 12, 2008 5:15 PM, ChairmanOfTheBored <[EMAIL PROTECTED]> wrote:
> On Sat, 12 Jan 2008 11:50:07 -0800 (PST), [EMAIL PROTECTED] wrote:
>
> >THERMUCK
>
>   Is a goddmned retard.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Why was this ever on the Python list (I assume it started as spam),
and why on earth has it continued?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: super, decorators and gettattribute

2008-01-12 Thread Richard Szopa
On Jan 12, 9:47 pm, Mike Meyer <[EMAIL PROTECTED]>
wrote:

> The same way you call any object's methods if you know it's name":
>
> getattr(super_object, name)(*args, **kwargs)

Thanks a lot for your answer!

However, I am very surprised to learn that

super_object.__getattr__(name)(*args, **kwargs)

getattr(super_object, name)(*args, **kwargs)

are not equivalent. This is quite odd, at least when with len()
and .__len__, str() and .__str__. Do you maybe know what's the
rationale behind not following that convention by getattr?

Best regards,

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


Re: *** American nationalism is FAKE and its MYTHS are LIES, YANK BASTARDS RAPED BY THEIR OWN MARINES - ***

2008-01-12 Thread Danyelle Gragsone
Can people people be banned from this list?  or the best way to handle
mailings of this such is to just block or foreword the individual
mailers to the trash bin?  It's content like this that makes a
wonderul list like this look bad

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


Re: where do my python files go in linux?

2008-01-12 Thread Jeroen Ruigrok van der Werven
Hi Jorgen,

-On [20080112 16:14], Jorgen Bodde ([EMAIL PROTECTED]) wrote:
>I thought about that too. I just wonder why /usr/local/bin is always
>empty and every .deb I install from a source (if it's from Ubuntu or
>not) installs files in /usr/bin .. So I looked further and noticed
>that most python files do reside in /usr/share/{appname}

Well, it always seemed that many Linux distributions had to do things
different from a file/directory hierarchy point of view and I never fully
understood why. It always seemed a bit inspired by NIH-syndrome.
But like I said, whatever works for you.

>I would agree but it is not a site package I am trying to distribute,
>but a wxPython application. I would not think my app belongs in the
>python site packages dir.

Mmm, I guess Python does not have a wonderful solution for this kind of
scenario to be honest. The site-packages solution is one of the cleanest I can
think of.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
Only I can change my life. No one can do it for me...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Is unicode.lower() locale-independent?

2008-01-12 Thread John Machin
On Jan 12, 11:26 pm, Torsten Bronger <[EMAIL PROTECTED]>
wrote:
> Hallöchen!
>
>
>
> Fredrik Lundh writes:
> > Robert Kern wrote:
>
> >>> However it appears from your bug ticket that you have a much
> >>> narrower problem (case-shifting a small known list of English
> >>> words like VOID) and can work around it by writing your own
> >>> locale-independent casing functions. Do you still need to find
> >>> out whether Python unicode casings are locale-dependent?
>
> >> I would still like to know. There are other places where .lower()
> >> is used in numpy, not to mention the rest of my code.
>
> > "lower" uses the informative case mappings provided by the Unicode
> > character database; see
>
> >http://www.unicode.org/Public/4.1.0/ucd/UCD.html
>
> > afaik, changing the locale has no influence whatsoever on Python's
> > Unicode subsystem.
>
> Slightly off-topic because it's not part of the Unicode subsystem,
> but I was once irritated that the none-breaking space (codepoint xa0
> I think) was included into string.whitespace.  I cannot reproduce it
> on my current system anymore, but I was pretty sure it occured with
> a fr_FR.UTF-8 locale.  Is this possible?  And who is to blame, or
> must my program cope with such things?

The NO-BREAK SPACE is treated as whitespace in the Python unicode
subsystem. As for str objects, the default "C" locale doesn't know it
exists; otherwise AFAIK if the character set for the locale has it, it
will be treated as whitespace.

You were irritated because non-break SPACE was included in
string.whiteSPACE? Surely not! It seems eminently logical to me.
Perhaps you were irritated because str.split() ignored the "no-break"?
If like me you had been faced with removing trailing spaces from text
columns in databases, you surely would have been delighted that
str.rstrip() removed the trailing-padding-for-nicer-layout no-break
spaces that the users had copy/pasted from some clown's website :-)

What was the *real* cause of your irritation?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3 is it in the python default distro?

2008-01-12 Thread Fredrik Lundh
Martin Marcher wrote:

> I can see that sqlite is in the standard lib documentation:
> http://docs.python.org/lib/module-sqlite3.html
> 
> however debian and ubuntu (and gentoo according to the packages info) seem
> _not_ to include it. 

http://packages.debian.org/python-sqlite



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


Re: sqlite3 is it in the python default distro?

2008-01-12 Thread Diez B. Roggisch
Martin Marcher schrieb:
> Hello,
> 
> I can see that sqlite is in the standard lib documentation:
> http://docs.python.org/lib/module-sqlite3.html
> 
> however debian and ubuntu (and gentoo according to the packages info) seem
> _not_ to include it. 
> 
> Now 2 question arise:
> 
> a) Is sqlite included in the python default distribution

Yes, since 2.5

> b) In real life can I consider (on linux) that an installation of python
> includes the sqlite stuff?

distutils is an example of a standard-module that gets ripped out of 
python by distros frequently, so that people need to install python-dev 
or such a package.

So - yes, it happens that distros don't deliver the whole standard 
distribution. Now I'm not sure if that happens for sqlite, but if your 
own tests show so (reminder: python 2.5, accidentially using earlier 
versions that are installed won't work of course), then the answer is - 
no, you can't

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


Re: where do my python files go in linux?

2008-01-12 Thread Carl Banks
On Sat, 12 Jan 2008 15:25:53 -0500, Mike Meyer wrote:

> On Sat, 12 Jan 2008 16:13:08 +0100 "Jorgen Bodde"
> <[EMAIL PROTECTED]> wrote:
>> > Normally you'd split up the bulk of the code into a module which gets
>> > installed into site-packages and a piece of stand-alone front-end
>> > code which imports the module and executes whatever you need to do
>> > and gets installed into a typical PATH directory.
>> I would agree but it is not a site package I am trying to distribute,
>> but a wxPython application. I would not think my app belongs in the
>> python site packages dir.
> 
> I suspect that's because your app is "simple", in that it only has one
> command. Many apps have multiple commands that share the same set of
> libraries. So putting a package for that app in site-packages makes a
> lot of sense.

They should go into their own directory in /usr/local/lib (or whatever).


> If your app-specific library is properly designed and
> documented, users may be able to build further commands for the system
> as well.

Users can still add the /usr/local/lib/whatever to their path path and 
use it that way.

I realize it's a fine line and a judgment call in some cases, but site-
packages is really for libraries; applications should use their own 
directories.


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


Re: Is unicode.lower() locale-independent?

2008-01-12 Thread John Machin
On Jan 12, 10:51 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Robert Kern wrote:
> >> However it appears from your bug ticket that you have a much narrower
> >> problem (case-shifting a small known list of English words like VOID)
> >> and can work around it by writing your own locale-independent casing
> >> functions. Do you still need to find out whether Python unicode
> >> casings are locale-dependent?
>
> > I would still like to know. There are other places where .lower() is used in
> > numpy, not to mention the rest of my code.
>
> "lower" uses the informative case mappings provided by the Unicode
> character database; see
>
>  http://www.unicode.org/Public/4.1.0/ucd/UCD.html

of which the relevant part is
"""
Case Mappings

There are a number of complications to case mappings that occur once
the repertoire of characters is expanded beyond ASCII. For more
information, see Chapter 3 in Unicode 4.0.

For compatibility with existing parsers, UnicodeData.txt only contains
case mappings for characters where they are one-to-one mappings; it
also omits information about context-sensitive case mappings.
Information about these special cases can be found in a separate data
file, SpecialCasing.txt.
"""

It seems that Python doesn't use the SpecialCasing.txt file. Effects
include:
(a) one-to-many mappings don't happen e.g. LATIN SMALL LETTER SHARP S:
u'\xdf'.upper() produces u'\xdf' instead of u'SS'
(b) language-sensitive mappings (e.g. dotted/dotless I/i for Turkish
(and Azeri)) don't happen
(c) context-sensitive mappings don't happen e.g. lower case of GREEK
CAPITAL LETTER SIGMA depends on whether it is the last letter in a
word.



>
> afaik, changing the locale has no influence whatsoever on Python's
> Unicode subsystem.
>
> 

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


Re: Great Python books for the beginner

2008-01-12 Thread [EMAIL PROTECTED]
On 12 jan, 21:04, Landon <[EMAIL PROTECTED]> wrote:
> One thing I wonder about is the examples these books use to teach the
> concepts. I found myself really attached to K&R because the end of
> section projects were utilities that I would find be able to find
> useful in day to day work such as a version of wc and a program that
> would take collapse all consecutive whitespace in a document into one
> space. I could just use the projects from K&R, but I imagine a Python
> book would have a better selection that highlight Python's abilities.

It wouldn't make any sens to port the K&R stuff to Python - different
languages, different uses, different problems... I mean, C is a low-
level language, mostly useful for low-level system programming, while
Python is a very high level language mostly useful for application
programming and Q&D scripting. So the applicative examples from K&R
are such no-brainers in Python they wouldn't teach you much, and the
more low-level examples (memory handling etc) just don't make sens in
Python because that's definitively not something you'd write in
Python.

But anyway: if you're looking for more real-life-like examples, Mark
Lutz's "Programming Python" might be worth a look.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Great Python books for the beginner

2008-01-12 Thread André
On Jan 12, 4:04 pm, Landon <[EMAIL PROTECTED]> wrote:
> One thing I wonder about is the examples these books use to teach the
> concepts. I found myself really attached to K&R because the end of
> section projects were utilities that I would find be able to find
> useful in day to day work such as a version of wc and a program that
> would take collapse all consecutive whitespace in a document into one
> space. I could just use the projects from K&R, but I imagine a Python
> book would have a better selection that highlight Python's abilities.
>
> On another note, I would prefer to have a paper book so I don't have
> to keep switching back and forth between documents on my computer.

You don't need to switch back and forth ... if you use Crunchy!

http://code.google.com/p/crunchy

To see it in action, 
http://showmedo.com/videos/video?name=143&fromSeriesID=143

(the third video in that series shows how to quickly get started using
the official Python tutorial).

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


Re: sqlite3 is it in the python default distro?

2008-01-12 Thread Gary Herron
Martin Marcher wrote:
> Hello,
>
> I can see that sqlite is in the standard lib documentation:
> http://docs.python.org/lib/module-sqlite3.html
>
> however debian and ubuntu (and gentoo according to the packages info) seem
> _not_ to include it. 
>
> Now 2 question arise:
>
> a) Is sqlite included in the python default distribution
> b) In real life can I consider (on linux) that an installation of python
> includes the sqlite stuff?
>
> thanks
> martin
>
>   
As I understand it, Python2.5 includes the *module* which can be
imported to access an sqlite installation, but it does not include the
sqlite installation itself.   That should be installed separately.   (I
suppose a distro of Linux could package them together, but I don't  know
of one that does, and such is not the intent of Python.)

Gary Herron

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


Re: super, decorators and gettattribute

2008-01-12 Thread Mike Meyer
On Sat, 12 Jan 2008 10:45:25 -0800 (PST) Richard Szopa <[EMAIL PROTECTED]> 
wrote:

> Hello all,
> 
> I am playing around w/ Python's object system and decorators and I
> decided to write (as an exercise) a decorator that (if applied to a
> method) would call the superclass' method of the same name before
> doing anything (initially I wanted to do something like CLOS
> [1] :before and :end methods, but that turned out to be too
> difficult).
> 
> However, I cannot get it right (specially, get rid of the eval). I
> suspect that I may be misunderstanding something happening between
> super objects and __getattribute__ methods.
> 
> Here's my code:
> 
> def endmethod(fun):
> """Decorator to call a superclass' fun first.
> 
> If the classes child and parent are defined as below, it should
> work like:
> 
> >>> x = child()
> >>> x.foo()
> I am parent's foo
> I am child's foo.
> """
> name = fun.__name__
> def decorated(self, *args, **kwargs):
> try:
> super_object = super(self.__class__, self)

There's an apparently common bug here: you don't want to pass super
self.__class__, but the class that the method is bound to. The two
aren't the same, as an instance of a subclass will have the subclass
as self.__class__, and not the current class. So super will return the
current class or a subclass of it, meaning (since you invoked this
method from self) you'll wind up invoking this method recursively.
All of which means your decorator is probably going to have to take
the class as an argument.

> # now I want to achieve something equivalent to calling
> # parent.foo(*args, **kwargs)
> # if I wanted to limit it only to this example
> 
> # this doesn't work: in the example, it calls child's foo,
> # entering in an eternal loop (instead of calling parent's
> # foo, as I would expect).
> 
> # super_object.__getattribute__(name)(*args, **kwargs)
> 
> # this does work, but I feel it's ugly
> eval('super_object.%s(*args, **kwargs)' % name)
> except AttributeError:
> pass # if parent doesn't implement fun, we don't care
>  # about it
> return fun(self, *args, **kwargs) # hopefully none
> 
> decorated.__name__ = name
> return decorated
> 
> 
> class parent(object):
> def foo(self):
> print 'I am parent\'s foo'
> 
> class child(parent):
> @endmethod
> def foo(self):
> print "I am foo\'s foo."
> 
> if __name__=='__main__':
> x = child()
> x.foo()
> 
> Can anybody tell me how to call a superclass method knowing its name?

The same way you call any object's methods if you know it's name":

getattr(super_object, name)(*args, **kwargs)

The code seems to work the way you want:

>>> x.foo()
I am parent's foo
I am foo's foo.

   http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


sqlite3 is it in the python default distro?

2008-01-12 Thread Martin Marcher
Hello,

I can see that sqlite is in the standard lib documentation:
http://docs.python.org/lib/module-sqlite3.html

however debian and ubuntu (and gentoo according to the packages info) seem
_not_ to include it. 

Now 2 question arise:

a) Is sqlite included in the python default distribution
b) In real life can I consider (on linux) that an installation of python
includes the sqlite stuff?

thanks
martin

-- 
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

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


Re: Simple List division problem

2008-01-12 Thread Paul Rubin
marcstuart <[EMAIL PROTECTED]> writes:
> what I would like to get is 3 sublists
> 
> print z[0] = [1,2,3]
> print z[2] = [4,5,6]
> print z[3] = [7,8,9,10]

Are you SURE you want that?  In almost every situation I've seen,

 print z[0] = [1,2,3]
 print z[2] = [4,5,6]
 print z[3] = [7,8,9]
 print z[4] = [10]

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


Re: where do my python files go in linux?

2008-01-12 Thread Mike Meyer
On Sat, 12 Jan 2008 16:13:08 +0100 "Jorgen Bodde" <[EMAIL PROTECTED]> wrote:
> > Normally you'd split up the bulk of the code into a module which gets
> > installed into site-packages and a piece of stand-alone front-end code which
> > imports the module and executes whatever you need to do and gets installed
> > into a typical PATH directory.
> I would agree but it is not a site package I am trying to distribute,
> but a wxPython application. I would not think my app belongs in the
> python site packages dir.

I suspect that's because your app is "simple", in that it only has one
command. Many apps have multiple commands that share the same set of
libraries. So putting a package for that app in site-packages makes a
lot of sense. If your app-specific library is properly designed and
documented, users may be able to build further commands for the system
as well.

On the issue of .pyc files - don't distribute them. Instead, arrange
for the install package to run the compileall.py script (in the
standard library) on your libraries. .pyc files are *not* guaranteed
to be platform independent (even though the latest rpm tools seem to
claim otherwise), so if you build them for your platform, they may
well be unusable after being installed.

   http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Great Python books for the beginner

2008-01-12 Thread Landon
One thing I wonder about is the examples these books use to teach the
concepts. I found myself really attached to K&R because the end of
section projects were utilities that I would find be able to find
useful in day to day work such as a version of wc and a program that
would take collapse all consecutive whitespace in a document into one
space. I could just use the projects from K&R, but I imagine a Python
book would have a better selection that highlight Python's abilities.

On another note, I would prefer to have a paper book so I don't have
to keep switching back and forth between documents on my computer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import and execfile()

2008-01-12 Thread Mike Meyer
On Fri, 11 Jan 2008 20:55:07 -0800 (PST) George Sakkis <[EMAIL PROTECTED]> 
wrote:
> On Jan 11, 5:24 pm, Mike Meyer <[EMAIL PROTECTED]>
> wrote:
> > On Fri, 11 Jan 2008 14:05:11 -0800 (PST) George Sakkis <[EMAIL PROTECTED]> 
> > wrote:
> > > I maintain a few configuration files in Python syntax (mainly nested
> > > dicts of ints and strings) and use execfile() to read them back to
> > > Python. This has been working great; it combines the convenience of
> > > pickle with the readability of Python. So far each configuration is
> > > contained in a single standalone file; different configurations are
> > > completely separate files.
> > You can make the syntax cleaner by using classes to hold the values
> > instead of nested dicts, etc. That way you don't have to quote the
> > names of the values:
> > class Foo:
> >   bar = 1
> >   baz = 2
> Actually I am using the dict() constructor instead of literals so it's
> as clean as with classes; IMO for nested options it's cleaner than
> nested classes:

Yup, that does that. Wasn't available last time I did this, so...
> > > I understand why this fails but I'm not sure how to tell execfile() to
> > > set the path accordingly. Any ideas ?
> > Manipulate sys.path yourself?
> That's what Mitko suggested too, and indeed it works:
> However this doesn't look very clean to me. Also it's not thread-safe;

I don't know that there is a clean solutions. As for not being
thread-safe, I'd suggest that you should have all your configuration
information loaded *before* you start any threads. This makes shutting
down in case you decide there's something wrong in it easier, and in
some cases may prevent inadvertently doing things that shouldn't
oughta be done. In the case where you config files are parsed by the
python interpreter, this goes double because a busted config file
could lead to exceptions, leaving your application in an unknown
state.

 http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple List division problem

2008-01-12 Thread [EMAIL PROTECTED]
On Jan 12, 12:37 pm, marcstuart <[EMAIL PROTECTED]> wrote:
> How do I divide a list into a set group of sublist's- if the list is
> not evenly dividable ?
> consider this example:
>
> x = [1,2,3,4,5,6,7,8,9,10]
> y = 3      # number of lists I want to break x into
> z = y/x
>
> what I would like to get is 3 sublists
>
> print z[0] = [1,2,3]
> print z[2] = [4,5,6]
> print z[3] = [7,8,9,10]
>
> obviously not even, one list will have 4 elements, the other 2 will
> have 3.,
> the overriding logic, is that I will get 3 lists and find a way for
> python to try to break it evenly, if not one list can have a greater
> amount of elements
>
> Would I use itertools ? How would I do this ?
>
> Thanks

def list_split(x,y):
  dm = divmod(len(x),y)
  if dm[1] != 0:
z = [x[i*y:i*y+y] for i in xrange(len(x)/y) if len(x[i*y:])>=2*y]
z.append(x[(len(x)/y-1)*y:])
  else:
z = [x[i*y:i*y+y] for i in xrange(len(x)/y)]
  return z

>>> list_split([1,2,3,4,5,6,7,8,9,10],3)
[[1, 2, 3], [4, 5, 6], [7, 8, 9, 10]]
>>> list_split([1,2,3,4,5,6,7,8,9,10],5)
[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
>>> list_split([1,2,3,4,5,6,7,8,9,10],4)
[[1, 2, 3, 4], [5, 6, 7, 8, 9, 10]]
>>> list_split([1,2,3,4,5,6,7,8,9,10],2)
[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too slow?

2008-01-12 Thread [EMAIL PROTECTED]
Oh.. it seems my naiveness has stirred quite a discussion >_<...

I must admit though, I've learned a bit about Python reading through
this topic.  Thanks to everyone who pointed out the flaws in the
code.  I'll see if I can come up with my own color tracking solution
in a few weeks and post back here.  Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Great Python books for the beginner

2008-01-12 Thread GeneralCody
On 2008-01-12 08:03:42 +0100, Landon <[EMAIL PROTECTED]> said:

> Hi, I'm a freshman in college and I'm going to be taking an intro to
> programming course next semester which mainly uses Python, so I
> thought it might be a good time to pick up Python beyond the scope of
> the class as well. The text book for this class is Python for the
> Absolute Beginner or something similar to that name.
> 
> I was wondering if anyone had any opinions on what other titles I
> could look into since this one seems from a glance at reviews to be
> teaching mainly through game programming (a topic I'm not too
> interested in) or if this one is a quality book by itself.

I would definetly go for Learning Python first, maybe Apress "Python, 
from novice to Professional" as well...

 

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


Re: Great Python books for the beginner

2008-01-12 Thread babycode
On Jan 12, 2:03 am, Landon <[EMAIL PROTECTED]> wrote:

> I was wondering if anyone had any opinions on what other titles I
> could look into since this one seems from a glance at reviews to be
> teaching mainly through game programming (a topic I'm not too
> interested in) or if this one is a quality book by itself.

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


Re: where do my python files go in linux?

2008-01-12 Thread Joe Riopel
On Jan 12, 2008 10:13 AM, Jorgen Bodde <[EMAIL PROTECTED]> wrote:
> I thought about that too. I just wonder why /usr/local/bin is always
> empty and every .deb I install from a source (if it's from Ubuntu or
> not) installs files in /usr/bin .. So I looked further and noticed
> that most python files do reside in /usr/share/{appname}

This link might explain why your /usr/local/bin is empty:

http://www.pathname.com/fhs/pub/fhs-2.3.html#THEUSRHIERARCHY
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE won't start in Python 2.5 for Windows

2008-01-12 Thread Fredrik Lundh
mikez302 wrote:

> I opened a command window in my Python25 folder and tried typing
> pythonw.  I just got another command prompt as if the program ran but
> didn't do anything.  It looked like this:
> 
> C:\Python25>pythonw
> 
> C:\Python25>

"pythonw" is the console-less version of the Python runtime, so that's 
expected.  Try using "python" instead.



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


Re: where do my python files go in linux?

2008-01-12 Thread Carl Banks
On Sat, 12 Jan 2008 12:02:20 +0100, Jorgen Bodde wrote:
> I am trying to make a debian package. I am following the tutorial by
> Horst Jens
> (http://showmedo.com/videos/video?
name=linuxJensMakingDeb&fromSeriesID=37)
> and it is very informative. However one thing my app has and his
> doesn't, is multiple python files which need to be executed. For example
> 
> {dir}/app
> app.py
> 
> app.py calls a lot of modules in {dir}/app. Horst says the python file
> goes in /usr/bin/app.py which is ok with me, but I have multiple python
> files, and I decided to use an app.sh script to call my python files. In
> the /usr/bin I do not see subdirs so I assume that is not really
> desirable.
> 
> Question 1. Where do I put the bulk of python scripts in a normal linux
> environment?
> Question 2. Should I use *.pyc rather then *.py files to speed up
> executing as the user cannot write to /usr/bin or any other dir in the
> system and everytime my app runs it will recompile it
> 
> Thanks for any advice or maybe a good tutorial how to set up files in a
> linux environment

On a Debian system:


I would put app.py in /usr/local/bin.  I would create the directory
/usr/local/lib/app, and put all other *.py and *.pyc files there.  At the 
top of app.py, I'd add the following line so that I could import files 
directly from /usr/local/lib/app:

sys.path.insert(0,'/usr/local/lib/app')


Alternatively, using your app.sh approach, I'd put app.sh in
/usr/local/bin/, and all *.py and *.pyc files in /usr/local/lib/app.  I'd 
invoke Python something like this:

PYTHONPATH=/usr/local/lib/app:$PYTHONPATH  python -m app

(The -m switch searches the Python path for a module to run.) 


If it's more of a library than an application (maybe there is a command 
line script, but users could want to import the modules directly), then 
I'd stick all the modules in /usr/local/lib/python2.x/site-packages, and 
the command line scripts in /usr/local/bin.


Yes, install the *.pyc files.  I recommend putting *.py files there as 
well, so users can refer to it if there are any problems, but you don't 
have to.  The Python module compileall is your friend here.


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


Re: Simple List division problem

2008-01-12 Thread Fredrik Lundh
marcstuart wrote:

> How do I divide a list into a set group of sublist's- if the list is
> not evenly dividable ?  consider this example:
> 
> x = [1,2,3,4,5,6,7,8,9,10]
> y = 3  # number of lists I want to break x into
> z = y/x
> 
> what I would like to get is 3 sublists
> 
> print z[0] = [1,2,3]
> print z[2] = [4,5,6]
> print z[3] = [7,8,9,10]
> 
> obviously not even, one list will have 4 elements, the other 2 will
> have 3.,

here's one way to do it:

# chop it up
n = len(x) / y
z = [x[i:i+n] for i in xrange(0, len(x), n)]

# if the last piece is too short, add it to one before it
if len(z[-1]) < n and len(z) > 1:
 z[-2].extend(z.pop(-1))



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


Re: Simple List division problem

2008-01-12 Thread Gary Herron
marcstuart wrote:
> How do I divide a list into a set group of sublist's- if the list is
> not evenly dividable ?
> consider this example:
>
> x = [1,2,3,4,5,6,7,8,9,10]
> y = 3  # number of lists I want to break x into
> z = y/x
>
>
> what I would like to get is 3 sublists
>
> print z[0] = [1,2,3]
> print z[2] = [4,5,6]
> print z[3] = [7,8,9,10]
>
> obviously not even, one list will have 4 elements, the other 2 will
> have 3.,
> the overriding logic, is that I will get 3 lists and find a way for
> python to try to break it evenly, if not one list can have a greater
> amount of elements
>
> Would I use itertools ? How would I do this ?
>
> Thanks
>   

Calculate the size of a normal sublist, and the amount of extra that
goes with the last sublist.
Then extract y-1 normal sized sublists and one possibly larger sublist.

>>> x = [1,2,3,4,5,6,7,8,9,10]
>>> y = 3
>>> s = len(x)/y
>>> s# size of normal sublists
3
>>> e = len(x) - y*s  # extra elements for last sublist
>>> e
1
>>> z = [x[s*i:s*i+s] for i in range(y-1)] + [x[-s-e:]] #extract y-1
normal + 1 larger sublists
>>> z
[[1, 2, 3], [4, 5, 6], [7, 8, 9, 10]]

Done!

Gary Herron





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


Re: Compiling fails on Mac OS X 10.5

2008-01-12 Thread Mark Dickinson
On Jan 12, 12:05 pm, mc <[EMAIL PROTECTED]> wrote:
> Alright!
> ./configure output is here:http://rafb.net/p/NqSmqc25.html
> and make output here:http://rafb.net/p/kzeb2e29.html

Hmm. Doesn't seem to be anything unusual here.  I was expecting to see
some more informative error message somewhere.  Does this output
definitely include everything sent to stderr and to stdout, or did it
come from just redirecting stdout?

I don't understand where all the

rm: conftest.dSYM: is a directory

lines in the configure output are coming from.  Can this possibly be
related?

Anyone else here have any ideas how to proceed?

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


Re: removeall() in list

2008-01-12 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> Will you engage with me over e-mail to discuss the Locker
> implementation I'm developing?  Aaron

I really can't, sorry.  I'm finding it hard enough to follow over the
newsgroup.  If you just have a single one of these lists, it's
probably simplest to do what Frederik Lundh suggested.  The other
stuff we've discussed is mostly about how to organize having a lot of
them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE won't start in Python 2.5 for Windows

2008-01-12 Thread mikez302
I opened a command window in my Python25 folder and tried typing
pythonw.  I just got another command prompt as if the program ran but
didn't do anything.  It looked like this:

C:\Python25>pythonw

C:\Python25>
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Import and execfile()

2008-01-12 Thread lloyd
Hello,

> I maintain a few configuration files in Python syntax (mainly nested

> dicts of ints and strings) and use execfile() to read them back to

> Python. This has been working great; it combines the convenience of

> pickle with the readability of Python. So far each configuration is

> contained in a single standalone file; different configurations are

> completely separate files.


> Now I'd like to factor out the commonalities of the different

> configurations in a master config and specify only the necessary

> modifications and additions in each concrete config file. I tried the

> simplest thing that could possibly work:

I've been working with a similar problem; indeed, posted a question about it 
several weeks ago.

I
can't speak to the issue of factoring out commonalities, but I've been
trying to find a really simple, elegant way to avoid the exec
functions. My approaches have been variations in __import__() and
loading as file, etc. Everything I've tried seems a bit kludgy. One
issue, as I recall, was that __import__() became rather unreliable when
you crossed directory boundaries.

Question: Why do so many sources discourage the use of exec(), execfile(), etc.?

Comment:
The Karrigell Python web framework
(http://karrigell.sourceforge.net/en/include.htm) has a truly elegant
function for loading stuff like some_config.py called Include(). I
haven't looked at the source, but it is very handy. I really wish it
was basic Python function.

All the best,

Lloyd



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

RE: where do my python files go in linux?

2008-01-12 Thread lloyd
Hello,

> Question 1. Where do I put the bulk of python scripts in a normal

> linux environment?

In my system I put them in
/usr/local/lib/python2.4/site-packages/my_scripts. And, I have *.pth
file in /usr/local/lib/python2.4/site-packages that points to
my_scripts. The *.pth file simply reads "my_scripts" -- without the
quotes, of course.

This one area where Python docs are pretty vague. It took me awhile to piece 
this together. But it works.

Best wishes,

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

Re: removeall() in list

2008-01-12 Thread castironpi
On Jan 12, 1:03 pm, Paul Rubin  wrote:
> [EMAIL PROTECTED] writes:
> > > Nothing else should have direct access to the list.
> > Impossible to guarantee in Python.  If you do, the reference to you does.
>
> Well, ok.  Nothing else should USE that access.

Ah, very agreed.  Access directly at your own risk.

Will you engage with me over e-mail to discuss the Locker
implementation I'm developing?  Aaron
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple List division problem

2008-01-12 Thread marcstuart
I have gotten a little further, but not in the order of the original
list

def divide_list(lst, n):
return [lst[i::n] for i in range(n)]

x = [1,2,3,4,5,6,7,8,9,10]
y = 3
z =  divide_list(x,y)

print z[0]
print z[1]
print z[2]


this prints:

[1, 4, 7, 10]
[2, 5, 8]
[3, 6, 9]



closer, but I would like to maintain the original order of the list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *** AMERICAN BASTARDS DESERVE TO BE RAPED ***

2008-01-12 Thread Joe Riopel
On Jan 12, 2008 2:00 PM, radiosrfun <[EMAIL PROTECTED]> wrote:
> Whether we agree on "tactics" or not - if it come to a battlefield with the
> two of us - or any Americans there - we're still going to fight the same
> enemy - not each other.

This is a good resource for starting Python
http://diveintopython.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: removeall() in list

2008-01-12 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> > Nothing else should have direct access to the list.
> Impossible to guarantee in Python.  If you do, the reference to you does.

Well, ok.  Nothing else should USE that access.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *** AMERICAN BASTARDS DESERVE TO BE RAPED ***

2008-01-12 Thread radiosrfun
"ChairmanOfTheBored" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Sat, 12 Jan 2008 10:35:38 -0500, "radiosrfun"
> <[EMAIL PROTECTED]> wrote:
>
>>"default" <[EMAIL PROTECTED]> wrote in message
>>news:[EMAIL PROTECTED]
>>> On Sat, 12 Jan 2008 02:01:09 -0500, "radiosrfun"
>>> <[EMAIL PROTECTED]> wrote:
>>>
I WISH - that the President and Congress of this country would shut off
ALL
foreign aid.
>>>
>>> Ditto that.
>>>
>>> Israel is the chief beneficiary of our foreign aid largesse.  Some 8
>>> billion dollars annually.  What doesn't find its way into politicians
>>> pockets goes to pay for a military that is winning us a lot of new
>>> friends in the Arab world.
>>>
>>> We pay Egypt ~ 2 billion a year in extortion to keep them from
>>> attacking Israel.
>>>
>>> The actually amount Israel receives is not really known to the public.
>>> The official numbers read something like 3 billion in aid, and another
>>> 5 billion in guaranteed loans - which are turned into grants year
>>> after year.  This is money we borrow so there's an additional interest
>>> burden.
>>>
>>> Actually when you talk about shutting off "foreign aid" you may be
>>> making thermate's point for him.
>>> --
>>
>>Well - the first cup of coffee hasn't exactly kicked in yet - but I 
>>believe
>>I know what you're saying and if correct - you may have a point there.
>>
>  You are both fucked in the head, coffee or not.  He more than you, but
> still, you both don't know what you are talking about.
>
>  If we stop giving aid to other nations, we are letting the retarded US
> hating bastards win, dipshit.
>

I'm not so sure I agree there - money or no money - they hate our guts. Case 
in point - Mushariff. It has long been rumored that Bin-Laden is lurking 
near by - yet "Mushariff" seems to be too weak in the knees to try to hunt 
him down or allow us to. If he doesn't have the balls to do it - let us! I 
am willing to bet - Bin - Laden will eventually cause Mushariff's downfall 
too.

>  This nation has to be strong within, DESPITE what we give out.
>

I couldn't agree with you more!

>  Some of us are...  some of us just want to piss and moan about things
> they know nothing about.
>

I DO know - I'm sick of our tax dollars being blown on every damned 
"emergency" abroad - and we get kicked in the teeth each and every time - 
following.

> Which do you think both of you fucktards are?

None of the above.

Chairman - I don't think "anyone" (American) will disagree with you - least 
of all me - that "WE" need to be strong from "within". The question comes - 
at what cost? IS it an investment? OR "Black mail"? In some cases - it could 
be a fine line.

I would find it hard to believe that 100% of our money is distributed to 
those who are "supposed" to get it. I think we would be fooling ourselves to 
think that.

Maybe I don't operate with "all" facts in hand - but up until now - you and 
I have pretty much been on the same page. Regardless which sentence or 
paragraph we parted company on - the fact remains - "I" am a U.S.citizen - 
born and raised here - and tired of the shit from all those piss ants. It is 
bad enough we have to put up with "crooked" politicians sucking us dry for 
all they can get - without the rest coming in to play their games.

We can agree to disagree with respect to "how" it is done - but we both want 
to see it "BE" done - for the benefit of this country. You and I - or anyone 
else can debate this in a friendly manner - or be pissed off at each other 
over it - the fact remains - those in charge will do as they please - and we 
have little say in the matter.

Any time some outsider slams this country or our people - it just pisses me 
off - which is why I bothered to reply to this thread at all.

Whether we agree on "tactics" or not - if it come to a battlefield with the 
two of us - or any Americans there - we're still going to fight the same 
enemy - not each other. 


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


Re: removeall() in list

2008-01-12 Thread castironpi
On Jan 12, 12:26 pm, Paul Rubin  wrote:
> [EMAIL PROTECTED] writes:
> > 2) List is referenced by others; concurrent modifications may be going
> > on; can not replace it.  Can I make asynchronous modifications and
> > merge the changes, SCM-style?
>
> Nothing else should have direct access to the list.
Impossible to guarantee in Python.  If you do, the reference to you
does.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: super, decorators and gettattribute

2008-01-12 Thread Richard Szopa
On Jan 12, 7:45 pm, Richard Szopa <[EMAIL PROTECTED]> wrote:

> doing anything (initially I wanted to do something like CLOS
> [1] :before and :end methods, but that turned out to be too
> difficult).

Erm, I meant :before and :after methods.

-- Richard

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


super, decorators and gettattribute

2008-01-12 Thread Richard Szopa
Hello all,

I am playing around w/ Python's object system and decorators and I
decided to write (as an exercise) a decorator that (if applied to a
method) would call the superclass' method of the same name before
doing anything (initially I wanted to do something like CLOS
[1] :before and :end methods, but that turned out to be too
difficult).

However, I cannot get it right (specially, get rid of the eval). I
suspect that I may be misunderstanding something happening between
super objects and __getattribute__ methods.

Here's my code:

def endmethod(fun):
"""Decorator to call a superclass' fun first.

If the classes child and parent are defined as below, it should
work like:

>>> x = child()
>>> x.foo()
I am parent's foo
I am child's foo.
"""
name = fun.__name__
def decorated(self, *args, **kwargs):
try:
super_object = super(self.__class__, self)

# now I want to achieve something equivalent to calling
# parent.foo(*args, **kwargs)
# if I wanted to limit it only to this example

# this doesn't work: in the example, it calls child's foo,
# entering in an eternal loop (instead of calling parent's
# foo, as I would expect).

# super_object.__getattribute__(name)(*args, **kwargs)

# this does work, but I feel it's ugly
eval('super_object.%s(*args, **kwargs)' % name)
except AttributeError:
pass # if parent doesn't implement fun, we don't care
 # about it
return fun(self, *args, **kwargs) # hopefully none

decorated.__name__ = name
return decorated


class parent(object):
def foo(self):
print 'I am parent\'s foo'

class child(parent):
@endmethod
def foo(self):
print "I am foo\'s foo."

if __name__=='__main__':
x = child()
x.foo()

Can anybody tell me how to call a superclass method knowing its name?

Thanks in advance,
-- Richard

[1] http://en.wikipedia.org/wiki/Common_Lisp_Object_System
-- 
http://mail.python.org/mailman/listinfo/python-list


Simple List division problem

2008-01-12 Thread marcstuart
How do I divide a list into a set group of sublist's- if the list is
not evenly dividable ?
consider this example:

x = [1,2,3,4,5,6,7,8,9,10]
y = 3  # number of lists I want to break x into
z = y/x


what I would like to get is 3 sublists

print z[0] = [1,2,3]
print z[2] = [4,5,6]
print z[3] = [7,8,9,10]

obviously not even, one list will have 4 elements, the other 2 will
have 3.,
the overriding logic, is that I will get 3 lists and find a way for
python to try to break it evenly, if not one list can have a greater
amount of elements

Would I use itertools ? How would I do this ?

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


Re: removeall() in list

2008-01-12 Thread castironpi
On Jan 12, 12:26 pm, Paul Rubin  wrote:
> [EMAIL PROTECTED] writes:
> > 2) List is referenced by others; concurrent modifications may be going
> > on; can not replace it.  Can I make asynchronous modifications and
> > merge the changes, SCM-style?
>
> Nothing else should have direct access to the list.
>
> > 3) Dictionary returns non-static order; order is important.  Create a
> > int-func tuple and sort dictionary results?  Perhaps.  That's sounding
> > pretty good.
>
> If the list is not too long, that is reasonable.  If it -is- long, the
> remove operations can be slow, but that's ok if there's not too many.
> If the list is long -and- there's a lot of adds/removes, maybe you
> want something like an AVL tree.

But items[ item ]= index is the best I can do in Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *** AMERICAN BASTARDS DESERVE TO BE RAPED ***

2008-01-12 Thread default
On Sat, 12 Jan 2008 09:15:44 -0800, ChairmanOfTheBored
<[EMAIL PROTECTED]> wrote:

> You are both fucked in the head, coffee or not.  He more than you, but
>still, you both don't know what you are talking about.

Any castigation from Bored is an accolade . . . I must be on the right
track to get that knee jerk reaction.
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: removeall() in list

2008-01-12 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> 2) List is referenced by others; concurrent modifications may be going
> on; can not replace it.  Can I make asynchronous modifications and
> merge the changes, SCM-style?

Nothing else should have direct access to the list.

> 3) Dictionary returns non-static order; order is important.  Create a
> int-func tuple and sort dictionary results?  Perhaps.  That's sounding
> pretty good.

If the list is not too long, that is reasonable.  If it -is- long, the
remove operations can be slow, but that's ok if there's not too many.
If the list is long -and- there's a lot of adds/removes, maybe you
want something like an AVL tree.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *** AMERICAN BASTARDS DESERVE TO BE RAPED ***

2008-01-12 Thread Richard Henry

"radiosrfun" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "default" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > On Sat, 12 Jan 2008 02:01:09 -0500, "radiosrfun"
> > <[EMAIL PROTECTED]> wrote:
> >
> >>I WISH - that the President and Congress of this country would shut off
> >>ALL
> >>foreign aid.
> >
> > Ditto that.
> >
> > Israel is the chief beneficiary of our foreign aid largesse.  Some 8
> > billion dollars annually.  What doesn't find its way into politicians
> > pockets goes to pay for a military that is winning us a lot of new
> > friends in the Arab world.
> >
> > We pay Egypt ~ 2 billion a year in extortion to keep them from
> > attacking Israel.
> >
> > The actually amount Israel receives is not really known to the public.
> > The official numbers read something like 3 billion in aid, and another
> > 5 billion in guaranteed loans - which are turned into grants year
> > after year.  This is money we borrow so there's an additional interest
> > burden.
> >
> > Actually when you talk about shutting off "foreign aid" you may be
> > making thermate's point for him.
> > --
>
> Well - the first cup of coffee hasn't exactly kicked in yet - but I
believe
> I know what you're saying and if correct - you may have a point there.

According to the US Govt for 2006:

Israel: $2.6B
Egypt   $1.8B
Iraq:   $9.8B
Afghanistan $3.7B

http://qesdb.usaid.gov/gbk/



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


Re: How to get user home directory on Windows

2008-01-12 Thread Giampaolo Rodola'
Update.
I found a way for getting the home directory of the user but it
requires to validate the user by providing username+password:

def get_homedir(username, password):
token = win32security.LogonUser(
username,
None,
password,
win32security.LOGON32_LOGON_NETWORK,
win32security.LOGON32_PROVIDER_DEFAULT
)
return win32profile.GetUserProfileDirectory(token)

What I'd like to do is avoiding the requirement of the password, the
same way as if I would on UNIX where it would be enough just using the
pwd module:

 >>> import pwd
 >>> pwd.getpwnam('user').pw_dir
 '/home/user'

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


Re: removeall() in list

2008-01-12 Thread castironpi
On Jan 12, 11:22 am, Rhamphoryncus <[EMAIL PROTECTED]> wrote:
> On Jan 12, 1:37 am, [EMAIL PROTECTED] wrote:
>
>
>
> > On Jan 11, 8:04 pm, Paul Rubin  wrote:
>
> > > [EMAIL PROTECTED] writes:
> > > > Could you:
>
> > > > lockerA= Locker( listA, listB )
> > > > lockerA.op( listB.reverse )
> > > > lockerA.op( listA.pop )
>
> > > > Where lockerA ops acquire the locks on all its threads?
>
> > > I don't understand that question.  The main thing to understand is
> > > that multi-threaded programming is complicated (especially if you're
> > > after high performance), and very difficult to get right without
> > > knowing exactly what you're doing.  The generally preferred approach
> > > in Python is to keep things simple at some performance cost.
>
> > > Your Locker approach above looks sort of reasonable if you can be
> > > absolutely sure that nothing else can mess with listA or listB
> > > concurrently with those locker operations.  Normally you would put
> > > listA and listB into a single object along with a lock, then do
> > > operations on that object.
>
> > > You might check the Python Cookbook for some specific recipes and
> > > sample code for this stuff.  If you've used Java, Python's general
> > > threading mechanisms are similar, but they are in the library rather
> > > than built into the language (i.e. there is no "synchronized"
> > > keyword, you have to do that locking explicitly).
>
> > > What is the actual application, if you don't mind saying?  Are you
> > > sure that you really need concurrency?
>
> > I'm writing an NxN observer pattern, mostly for my own personal
> > exploration.  Two threads -might- be calling 'Disconnect' at the same
> > time, and I can't even guarantee that the function runs properly.
>
> > for emelem in [ e for e in emlist if e.func is func ]:
> > try:
> > emlist.remove( emelem )
> > except ValueError:
> > pass
>
> Is there a reason you're using a list, rather than a dict?  Note that
> each call to list.remove() is O(n), whereas deleting a key from a dict
> is O(1).

4.  List-only solution:
Use a dictionary, map item to its index.
To retrieve, sort on value, not key

Sure: you need to maintain order of the things you're guarding.  I
need this to happen first, then this second.  My application is event
callbacks, that you register in a certain order; think GUIs and the
Gamma et al. Chain of Responsibility pattern.  This is a circumstance;
in a lot of applications order doesn't matter and you can use a hash.

But even so, you still can't check membership during concurrent
operation.  In other words, to remove all elements E such that E.func
is FuncF, the simple
   for e in setofe[:]:
  if e.func is not FuncF: continue
  setofe.remove( e )
still doesn't work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: removeall() in list

2008-01-12 Thread Rhamphoryncus
On Jan 12, 1:37 am, [EMAIL PROTECTED] wrote:
> On Jan 11, 8:04 pm, Paul Rubin  wrote:
>
>
>
> > [EMAIL PROTECTED] writes:
> > > Could you:
>
> > > lockerA= Locker( listA, listB )
> > > lockerA.op( listB.reverse )
> > > lockerA.op( listA.pop )
>
> > > Where lockerA ops acquire the locks on all its threads?
>
> > I don't understand that question.  The main thing to understand is
> > that multi-threaded programming is complicated (especially if you're
> > after high performance), and very difficult to get right without
> > knowing exactly what you're doing.  The generally preferred approach
> > in Python is to keep things simple at some performance cost.
>
> > Your Locker approach above looks sort of reasonable if you can be
> > absolutely sure that nothing else can mess with listA or listB
> > concurrently with those locker operations.  Normally you would put
> > listA and listB into a single object along with a lock, then do
> > operations on that object.
>
> > You might check the Python Cookbook for some specific recipes and
> > sample code for this stuff.  If you've used Java, Python's general
> > threading mechanisms are similar, but they are in the library rather
> > than built into the language (i.e. there is no "synchronized"
> > keyword, you have to do that locking explicitly).
>
> > What is the actual application, if you don't mind saying?  Are you
> > sure that you really need concurrency?
>
> I'm writing an NxN observer pattern, mostly for my own personal
> exploration.  Two threads -might- be calling 'Disconnect' at the same
> time, and I can't even guarantee that the function runs properly.
>
> for emelem in [ e for e in emlist if e.func is func ]:
> try:
> emlist.remove( emelem )
> except ValueError:
> pass

Is there a reason you're using a list, rather than a dict?  Note that
each call to list.remove() is O(n), whereas deleting a key from a dict
is O(1).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too slow?

2008-01-12 Thread [EMAIL PROTECTED]
On 10 jan, 03:10, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Wed, 09 Jan 2008 21:26:05 +0100, Bruno Desthuilliers wrote:
> > hint: how can a compiler safely optimize anything in a language so
> > dynamic that even the class of an object can be changed at runtime ?
>
> Is that a trick question?
>
Nope. Just an observation about the tradeoffs of dynamism.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling fails on Mac OS X 10.5

2008-01-12 Thread mc
On Jan 12, 5:34 pm, Mark Dickinson <[EMAIL PROTECTED]> wrote:
> On Jan 12, 9:41 am, mc <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi!
> > I'm trying to compile on my Macbook with OS X 10.5. I have all updates
> > and Xcode 3.0 installed.
>
> > I checked python out with: svn 
> > checkouthttp://svn.python.org/projects/python/branches/py3k
> > After that I did "./configure" in the  created "py3k" dir. Everything
> > went fine. But make fails with the following error message:
> > ranlib libpython3.0.a
> > gcc  -u _PyMac_Error -o python.exe \
> > Modules/python.o \
> > libpython3.0.a -ldl
> > make: *** [sharedmods] Error 1
>
> > I tried checking out many times. I also tried de 3.0a2 release,gives
> > me the same error. I've heard others have compiled it successfully on
> > Leopard so I wonder what causes the problems on my system.
>
> Could you post the rest of the ./configure and compilation output?
> make might be rereporting an error that occurred further up.
>
> I don't see anything related on the Python bug tracker.  It might be
> worth posting a bug report at bugs.python.org
>
> Mark


Alright!
./configure output is here: http://rafb.net/p/NqSmqc25.html
and make output here: http://rafb.net/p/kzeb2e29.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too slow?

2008-01-12 Thread [EMAIL PROTECTED]
On 10 jan, 21:47, Ed Jensen <[EMAIL PROTECTED]> wrote:
> Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> > I fail to see how the existence of JIT compilers in some Java VM changes
> > anything to the fact that both Java (by language specification) and
> > CPython use the byte-code/VM scheme.
>
> While your answer was technically correct, by omitting pertinent
> information, your answer lead readers to the wrong conclusion.

That's pure non-sense.

> The only question that remains is if you were being accidentally
> misleading or purposefully misleading.

The only question that remains for me is if you are being just stupid
or totally paranoid.

fu2 /dev/null
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too slow?

2008-01-12 Thread [EMAIL PROTECTED]
On 11 jan, 17:23, Ed Jensen <[EMAIL PROTECTED]> wrote:
> Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> > fact 1: CPython compiles source code to byte-code.
> > fact 2: CPython executes this byte-code.
> > fact 3: Sun's JDK compiles source code to byte-code.
> > fact 4: Sun's JDK executes this byte-code.
>
> > Care to prove me wrong on any of these points ? Don't bother: you can't.
> > So my first assertion that "CPython is compiled to byte-code, which is
> > then executed by a VM" is true, and since the same assertion also stands
> > for Java (ie: sun's JDK), then the "just like" qualifier is true too.
> > Period.
>
> #2 and #4 are wrong (or, at best, misleading).  Here, I'll fix them
> for you:
>
> Fact 2: CPython interprets the bytecode.
>
> Fact 4: Sun's JVM does some interpretation of the bytecode, but also
> compiles some of the bytecode to native code and executes the
> resulting native code.
>
> These distinctions can be important and it's intellectually dishonest
> to gloss over them.

These distinctions are important if the context is the VM
implementation, which is *obviously* not the case here. FWIW, I you
had spent a bit more time reading the remaining of the discussion with
the OP, I do clearly mention this distinction. So please get a life
and keep your comment about "intellectual dishonesty" where they
belong.
-- 
http://mail.python.org/mailman/listinfo/python-list


a problem with py2exe

2008-01-12 Thread [EMAIL PROTECTED]
I wrote an app that uses some Tix widgets and wanted to make an exe
using py2exe .i used the setup script as given in 
http://www.py2exe.org/index.cgi/TixSetup
and it copies the dlls into the dist directory created by py2exe.
But then the application works only if i create a directory named
'DLLs ' and copy the tix84.dll alone into that directory. it seems
silly to have tix84.dll in that dir and all other dlls in the dist
directory.can anyone advise me if i can run the app with all dlls in
one directory.
the  setup script i used is below

import glob,os,sys
from distutils.core import setup
import py2exe

def files(folder):
for path in glob.glob(folder+'/*'):
if os.path.isfile(path):
yield path

data_files=[
('.', glob.glob(sys.prefix+'/DLLs/tix84.dll')),
('tcl/tix8.4', files(sys.prefix+'/tcl/tix8.4')),
('tcl/tix8.4/bitmaps',
files(sys.prefix+'/tcl/tix8.4/bitmaps')),
('tcl/tix8.4/pref',
files(sys.prefix+'/tcl/tix8.4/pref')),
]

setup(
script_args=['py2exe'],
windows=['pyfaces.py'],
data_files=data_files
)

thanx in adv
dn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too slow?

2008-01-12 Thread [EMAIL PROTECTED]
On 11 jan, 15:41, Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
> Bruno Desthuilliers <[EMAIL PROTECTED]>
> writes:
>
> > fact 1: CPython compiles source code to byte-code.
> > fact 2: CPython executes this byte-code.
> > fact 3: Sun's JDK compiles source code to byte-code.
> > fact 4: Sun's JDK executes this byte-code.
>
> > Care to prove me wrong on any of these points ? Don't bother: you
> > can't.
>
> Fact 4 is misleading because it is only one option available to Sun's
> JDK.  Sun's JDK is also capable of transforming the byte-code to
> native code and letting the processor execute that instead of the
> original byte code, and that is where the most significant speed
> increase comes from.  Most importantly, it does so automatically, by
> default, with no programmer intervention or configuration, and with
> 100% compatibility, so it doesn't compare well to Python accelerators
> like psyco.

Then fact 1 is misleading too since Python handles the compilation
automatically without programmer's intervention while Java requires
someone to explicitely invoke the byte-code compiler.

I just don't understand what's all that fuss with this simple and
quite comparison of Java and Python. You can google this ng archives,
you'll find hundreds of posts saying the same thing, and everyone so
far seemed to be smart enough to understand that this had nothing to
do with the byte-code specifications, VM implementation and presence
or absence of a JIT compiler.

Anyway, I do maintain that what I said is 100% correct, 100% accurate
given the context, and 0% misleading unless you're clueless enough to
not be able to parse a single english sentence (in which case I just
can't help). As a matter of fact, this didn't seem to "mislead" the OP
into thinking such a thing.

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


Re: How to get user home directory on Windows

2008-01-12 Thread Giampaolo Rodola'
On 12 Gen, 17:44, Christian Heimes <[EMAIL PROTECTED]> wrote:
> Giampaolo Rodola' wrote:
> > Is there a way to do that?
>
> home = os.path.expanduser("~")
>
> Christian

That gives the home of the *current logged in user*.
I need another thing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too slow?

2008-01-12 Thread Paul Boddie
On 12 Jan, 04:03, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
>
> Given the way that people seem to use "interpreted" as a pejorative and a
> synonym for "slow", I don't doubt it one bit. Especially in management,
> where they might be making technical judgments on the basis of half-
> remembered Comp Sci 101 lessons from fifteen years earlier and vague
> buzzword-laden articles in trade magazines.

Indeed. Still, there's reason to be upbeat about Python's potential
here. The big question is this: what is everyone with any degree of
concern about Python's performance doing to improve the situation?
Sure, C (or actually C++) seems to win the shootout [1], but there are
plenty of language implementations between g++ and CPython to suggest
that the old choice of extension modules written in C vs. other code
written in Python doesn't provide a complete map of the opportunities.

Paul

[1] http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=all&lang=all
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python too slow?

2008-01-12 Thread [EMAIL PROTECTED]
On 11 jan, 16:10, George Sakkis <[EMAIL PROTECTED]> wrote:
> On Jan 11, 8:59 am, Bruno Desthuilliers  > But I *still* fail to see how it could be "misleading", and
> > *you* still fail to explain in which way it could be misleading.
>
> > If your point is that saying that CPython uses a byte-code/VM scheme
> > "just like Java" necessarily implies JIT compilation just because some
> > JVM support this feature, then it would be time you pay more attention
> > to what is effectively written.
>
> What three different people in this thread have been trying to tell
> you but you seem to miss is that claiming CPython's VM "is just like
> Java"

George, *please*, re-read what I wrote. I *never* claimed that
CPython's VM is just like a JVM, I just stated that both CPython and
Java use a byte-code/VM execution model. Can't you understand that ?

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


Re: How to get user home directory on Windows

2008-01-12 Thread Christian Heimes
Giampaolo Rodola' wrote:
> Is there a way to do that?

home = os.path.expanduser("~")

Christian

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


what did the bible say about Mohammad

2008-01-12 Thread small giant
According to the Bible, God said to Moses, on whom be peace: I will
raise up for them a prophet like you from among their brothers; I will
put my words in his mouth, and he will tell them everything I command
him. (The Holy Bible, New International Version, Deuteronomy chapter
18, verse 18). The prophet described in the above verse must have the
following three characteristics: 1. He will be like Moses. 2. He will
come from the brothers of the Israelites, i.e. the Ishmaelites. 3. God
will put His words in the mouth of the prophet and he will declare
what God commanded him. Let us see which prophet God was speaking of.
1. The prophet like Moses Some people feel that this prophecy refers
to the prophet Jesus, on whom be peace. But, although Jesus (peace be
upon him and all of God's prophets and messengers) was truly a prophet
of God, he is not the prophet spoken of here. He was born
miraculously, and finally God raised him up miraculously. On the other
hand, Muhammad is more like Moses; both were born in a natural way and
both died natural deaths.

2. From among the Ishmaelites Abraham had two sons, Ishmael and Isaac
(Genesis, chapter 21). Ishmael became the grandfather of the Arab
nation. And Isaac became the grandfather of Jewish nation. The prophet
spoken of was to come not from among the Jews themselves, but from
among their brothers, the Ishmaelites. Muhammad a descendant of
Ishmael, is indeed that prophet. 3. God will put his words in his
mouth 'Neither the content of the revelation, nor its form, were of
Muhammad's devising. Both were given by the angel, and Muhammad's task
was only to repeat what he heard.' (Word Religions from Ancient
history to the Present, by Geoffrey Parrinder, p. 472). God sent the
angel Gabriel to teach Muhammad the exact words that he should repeat
to the people. The words are therefore not his own; they did not come
from his own thoughts, but were put into his mouth by the angel. These
are written down in the Qur'an word for word, exactly as they came
from God. Now that we know that prophet we must listen to him, for,
according to the Bible, God says: 'I will punish anyone who refuses to
obey him' (Good News Bible, Deut. 18:19). Jesus (on whom be peace) In
the Glorious Qur'an The Qur'an tells us many wonderful things about
Jesus. As a result, believers in the Qur'an love Jesus, honor him and
believe in him. In fact, no Muslim can be a Muslim unless he or she
believes in Jesus, on whom be peace. The Qur'an says that Jesus was
born of a virgin, that he spoke while he was still only a baby, that
he healed the blind and the leper by God's leave and that he raised
the dead by God's leave. What then is the significance of these
miracles? First, the virgin birth. God demonstrates His power to
create in every way. God created everyone we know from a man and a
woman. But how about Adam, on whom be peace? God created him from
neither a man nor a woman. And Eve from only a man, without a woman.
And finally, to complete the picture, God created Jesus from a woman,
without a man. What about the other miracles? These were to show that
Jesus was not acting on his own behalf, but that he was backed by God.
The Qur'an specifies that these miracles were performed by God's
leave. This may be compared to the Book of Acts in the Bible, chapter
2, verse 22, where it says that the miracles were done by God to show
that he approved of Jesus. Also, note that Jesus himself is recorded
in the Gospel of John to have said: 'I can do nothing of my own
authority' (5:30). The miracles, therefore, were done not by his own
authority, but by God's authority. What did Jesus teach? The Qur'an
tells us that Jesus came to teach the same basic message which was
taught by previous prophets from God - that we must shun every false
god and worship only the One True God. Jesus taught that he is the
servant and messenger of the One True God, the God of Abraham. These
Qur'anic teachings can be compared with the Bible (Mark 10:18; Matthew
26:39; John 14:28, 17:3, and 20:17) where Jesus teaches that the one
he worshipped is the only true God. See also Matthew 12:18; Acts 3:13,
and 4:27 where we find that his disciples knew him as 'Servant of
God'. The Qur'an tells us that some of the Israelites rejected Jesus,
and conspired to kill him, but God rescued Jesus and raised him to
Himself. God will cause Jesus to descend again, at which time Jesus
will confirm his true teachings and everyone will believe in him as he
is and as the Qur'an teaches about him. Jesus is the Messiah. He is a
word from God, and a spirit from Him. He is honored in this world and
in the hereafter, and he is one of those brought nearest to God. Jesus
was a man who spoke the truth which he heard from God. This can be
compared with the Gospel According John where Jesus says to the
Israelites: 'You are determined to kill me, a man who has told you the
truth that I heard from God' (John 8:40).

see this site www.sultan.org
-- 
http://mail.python.org/mailman/

Re: Compiling fails on Mac OS X 10.5

2008-01-12 Thread Mark Dickinson
On Jan 12, 9:41 am, mc <[EMAIL PROTECTED]> wrote:
> Hi!
> I'm trying to compile on my Macbook with OS X 10.5. I have all updates
> and Xcode 3.0 installed.
>
> I checked python out with: svn 
> checkouthttp://svn.python.org/projects/python/branches/py3k
> After that I did "./configure" in the  created "py3k" dir. Everything
> went fine. But make fails with the following error message:
> ranlib libpython3.0.a
> gcc  -u _PyMac_Error -o python.exe \
>                         Modules/python.o \
>                         libpython3.0.a -ldl
> make: *** [sharedmods] Error 1
>
> I tried checking out many times. I also tried de 3.0a2 release,gives
> me the same error. I've heard others have compiled it successfully on
> Leopard so I wonder what causes the problems on my system.

Could you post the rest of the ./configure and compilation output?
make might be rereporting an error that occurred further up.

I don't see anything related on the Python bug tracker.  It might be
worth posting a bug report at bugs.python.org

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


How to get user home directory on Windows

2008-01-12 Thread Giampaolo Rodola'
Hi all,
I'm trying to use the pywin32 extension to find out the user's home
directory but currently I didn't find a solution yet.
What I'd need to do is not getting the home directory of the currently
logged in user but something like:

>>> get_homedir("frank")
"C:\home\users\frank"
>>> get_homedir("josh")
"C:\home\users\josh"

Is there a way to do that?
I tried to search through the Pywin32 documentation with no luck.
In addition I'm not practiced with the Windows API at all.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where do my python files go in linux?

2008-01-12 Thread Grant Edwards
On 2008-01-12, Jorgen Bodde <[EMAIL PROTECTED]> wrote:

>> Normally you'd split up the bulk of the code into a module which gets
>> installed into site-packages and a piece of stand-alone front-end code which
>> imports the module and executes whatever you need to do and gets installed
>> into a typical PATH directory.
>
> I would agree but it is not a site package I am trying to distribute,
> but a wxPython application. I would not think my app belongs in the
> python site packages dir.

That's my opinion also, but I've seen several apps that are
distributed that way.  The bulk of the application code goes
into the site-packages directory and then there's a 5-line
script in /usr/bin that calls the application's main module
that's in site-packages.

That seems wrong to me...

-- 
Grant Edwards   grante Yow!  Civilization is
  at   fun! Anyway, it keeps
   visi.comme busy!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: removeall() in list

2008-01-12 Thread castironpi
On Jan 12, 8:04 am, [EMAIL PROTECTED] wrote:
> On Jan 11, 5:26 pm, Paul Rubin  wrote:
>
> > [EMAIL PROTECTED] writes:
>
> > 1. Put a single thread in charge of the list, and communicate with it
> > by message passing through Queues.  To get X out of the list, you'd
> > send the mutator thread a message asking for removal.  The mutator
> > thread would loop reading and processing messages from the queue,
> > blocking when no requests are pending.  This is sort of the preferred
> > Python style and is pretty simple to get correct, but if there are
> > many such objects you can end up with more threads than you really
> > want.
>
> I've heard this called 'fire and forget'.  You can insure that
> mutations are honored one-at-a-time  and in the order received.  How
> do you make a -read- operation; wait for queued mutations, that is
> lock for a turn on the queue?  Can you optionally read whatever the
> state is, regardless of what's happened in the meantime?  Thing is,
> one thread needs its -own- preceding operations completed before a
> reading operation.

Brainstorm.

First, isolation of problem:  Terminates at 2000 or so, on my
computer.

import thread
import time
import random
counter= 0
def simplecounter():
global counter
ret= counter
counter+= 1
time.sleep( random.uniform( 0, .001 ) )
return counter
glist= []
def th3():
while 1:
ret= simplecounter()
glist.append( ret )
print ret,
assert glist== range( 1, len( glist )+1 )
thread.start_new_thread( th3, () )
time.sleep(1)
thread.start_new_thread( th3, () )
time.sleep( 1000 )

Second, the thoughts:  'with a.callbacklock():' looks best currently.

'''multithreading ideas:
1.  Put a single thread in charge
a.k.a. fire and forget.
- Lots of extra threads
+ But most are blocking most of the time
+ honored one-at-a-time, and in order received
+ ...optionally including read-access, blocking on
to get return values
a. synchronous callbacks, for read-access
+ multi-step, user-definitionized operations
- one consumer can hang an entire object
i.  with a.callbacklock():?
+ only call acquire() from curr. thread, enqueue
lock obj., released from producer thread "soon"
using message-queue semantics
b. mini-transaction, guarantees all and only
consumer's ops occur in succession
- can't do anything amidst an indivdual locking
- no multi-step ops
2.  Lock mutation and/or all operations
a. Locker.op
b. with Locker.withop
- In Python, other programmers always have access
to your data; nothing guarantees they'll use "with locker"
+ User-definitioning quite easy
3.  @mutation decorator
def mutation( func ):
def newfunc( self, *a, **k ):
self.lock.acquire()
func( *a, **k )
self.lock.release()
4.  List-only solution:
Use a dictionary, map item to its index.
To retrieve, sort on value, not key
'''
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *** AMERICAN BASTARDS DESERVE TO BE RAPED ***

2008-01-12 Thread radiosrfun
"default" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Sat, 12 Jan 2008 02:01:09 -0500, "radiosrfun"
> <[EMAIL PROTECTED]> wrote:
>
>>I WISH - that the President and Congress of this country would shut off 
>>ALL
>>foreign aid.
>
> Ditto that.
>
> Israel is the chief beneficiary of our foreign aid largesse.  Some 8
> billion dollars annually.  What doesn't find its way into politicians
> pockets goes to pay for a military that is winning us a lot of new
> friends in the Arab world.
>
> We pay Egypt ~ 2 billion a year in extortion to keep them from
> attacking Israel.
>
> The actually amount Israel receives is not really known to the public.
> The official numbers read something like 3 billion in aid, and another
> 5 billion in guaranteed loans - which are turned into grants year
> after year.  This is money we borrow so there's an additional interest
> burden.
>
> Actually when you talk about shutting off "foreign aid" you may be
> making thermate's point for him.
> --

Well - the first cup of coffee hasn't exactly kicked in yet - but I believe 
I know what you're saying and if correct - you may have a point there. 


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


Re: where do my python files go in linux?

2008-01-12 Thread Faber J. Fedor
On 12/01/08 12:02 +0100, Jorgen Bodde wrote:
> Hi All,
> 
> I am trying to make a debian package. I am following the tutorial by
> Horst Jens 
> (http://showmedo.com/videos/video?name=linuxJensMakingDeb&fromSeriesID=37)
> and it is very informative. However one thing my app has and his
> doesn't, is multiple python files which need to be executed. For
> example
> 
> {dir}/app
> app.py
> 
> app.py calls a lot of modules in {dir}/app. Horst says the python file
> goes in /usr/bin/app.py which is ok with me, but I have multiple
> python files, and I decided to use an app.sh script to call my python
> files. In the /usr/bin I do not see subdirs so I assume that is not
> really desirable.
> 
> Question 1. Where do I put the bulk of python scripts in a normal
> linux environment?

I would think you'd create a directory /usr/bin/app and then symlink
/usr/bin/app.py to /usr/bin/app/app.py.


> Question 2. Should I use *.pyc rather then *.py files to speed up
> executing as the user cannot write to /usr/bin or any other dir in the
> system and everytime my app runs it will recompile it

That would make sense.

> Thanks for any advice or maybe a good tutorial how to set up files in
> a linux environment

http://www.pathname.com/fhs/ (couldn't find a more
recent version, sorry.)


-- 
 
Regards,
 
Faber Fedor
President
Linux New Jersey, Inc.
908-320-0357
800-706-0701

http://www.linuxnj.com




-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

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


Re: where do my python files go in linux?

2008-01-12 Thread Jorgen Bodde
Hi Jeroen,

Thanks for the advice.

> Personally I'd be loathe to put app.py in /usr/bin. This directory is normally
> reserved for OS-specific binaries. For personal/system-extended stuff I'd use
> /usr/local/bin or whatever your system mandates. (But hey, that's the typical
> mentality difference between the BSD and Linux world it seems, so do with it
> what you want.)

I thought about that too. I just wonder why /usr/local/bin is always
empty and every .deb I install from a source (if it's from Ubuntu or
not) installs files in /usr/bin .. So I looked further and noticed
that most python files do reside in /usr/share/{appname}

> Normally you'd split up the bulk of the code into a module which gets
> installed into site-packages and a piece of stand-alone front-end code which
> imports the module and executes whatever you need to do and gets installed
> into a typical PATH directory.

I would agree but it is not a site package I am trying to distribute,
but a wxPython application. I would not think my app belongs in the
python site packages dir.

Thanks a lot for the input!

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


Compiling fails on Mac OS X 10.5

2008-01-12 Thread mc
Hi!
I'm trying to compile on my Macbook with OS X 10.5. I have all updates
and Xcode 3.0 installed.

I checked python out with: svn checkout 
http://svn.python.org/projects/python/branches/py3k
After that I did "./configure" in the  created "py3k" dir. Everything
went fine. But make fails with the following error message:
ranlib libpython3.0.a
gcc  -u _PyMac_Error -o python.exe \
Modules/python.o \
libpython3.0.a -ldl
make: *** [sharedmods] Error 1

I tried checking out many times. I also tried de 3.0a2 release,gives
me the same error. I've heard others have compiled it successfully on
Leopard so I wonder what causes the problems on my system.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Great Python books for the beginner

2008-01-12 Thread Mike
On Jan 12, 7:47 am, Ben Finney <[EMAIL PROTECTED]>
wrote:
> Landon <[EMAIL PROTECTED]> writes:
> > I was wondering if anyone had any opinions on what other titles I
> > could look into since this one seems from a glance at reviews to be
> > teaching mainly through game programming (a topic I'm not too
> > interested in) or if this one is a quality book by itself.
>
> The book "Learning Python" is currently proving very useful to an
> associate of mine. I'm watching his knowledge of Python grow
> substantially every week, from what was an essentially zero start.
>
> Learning Python, 3rd Edition
> Mark Lutz
> O'Reilly
> http://www.oreilly.com/catalog/9780596513986/>
>
> Looking through the text, it is very well structured, thoroughly
> teaching all the fundamentals of the language and types and idioms
> while referring back to already-learned material. The author makes a
> living training people in Python, and the third edition has benefited
> from his many years of experience finding effective ways to teach the
> language.
>
> --
>  \ "If you ever teach a yodeling class, probably the hardest thing |
>   `\  is to keep the students from just trying to yodel right off. |
> _o__)  You see, we build to that."  -- Jack Handey |
> Ben Finney

I would recommend Lutz's other book, the wonderful Python tome
"Programming Python 3rd Ed." as well. It's good for getting into the
deepest part of Python's jungle.

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


Re: Great Python books for the beginner

2008-01-12 Thread sween119
On Jan 12, 2:03 am, Landon <[EMAIL PROTECTED]> wrote:
> Hi, I'm a freshman in college and I'm going to be taking an intro to
> programming course next semester which mainly uses Python, so I
> thought it might be a good time to pick up Python beyond the scope of
> the class as well. The text book for this class is Python for the
> Absolute Beginner or something similar to that name.
>
> I was wondering if anyone had any opinions on what other titles I
> could look into since this one seems from a glance at reviews to be
> teaching mainly through game programming (a topic I'm not too
> interested in) or if this one is a quality book by itself.

Hi Landon,

I've found the O'reilly books to be useful I have the Python Pocket
reference, which is helpful for me to remember the parameters
surrounding commands and all that.

I've been known to peruse the "Learning Python" book by the same
publisher and I really like "Programming Python" (though it is
thoroughly hefty and runs about $60USD)

But  has excellent documentation and if I may
put a word in for  to check out if you would be
at all interested in starting game programming.

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


Re: executing newgrp from python in current shell possible?

2008-01-12 Thread Svenn Are Bjerkem
On Jan 9, 9:18 pm, Zentrader <[EMAIL PROTECTED]> wrote:
> On Jan 9, 5:56 am, Svenn Are Bjerkem <[EMAIL PROTECTED]>
> wrote:
>
> >I have been looking for a way to execute this command
> > as a part of a script, but it seems that the changes are only valid in
> > the context of the script and when the script exits, the current shell
> > still have the original "users" group setting.
>
> I don't think you would want it any other way.  Would you want a user
> to be able to change the group and have it remain permanently?  Who's
> going to remember whether they were last in "A" or "B", and it opens
> up oportunities for the practical joker when you go to the restroom
> and leave the terminal on.  Put the "change the group" code into a
> separate function in a separate file (with only you as the owner) and
> call it whenever you want to change groups.

I am trying to create a script that make it easy for users in a design
team to create files that belong to the same group, but retain the
users uid. In order to make it visible that the user is creating files
with a different gid, the script will change the prompt to indicate
so. In a tcl solution I have now, the users home is changed to the
design area as some tools are reading and writing setup files into
$HOME. I have not found a way to change the gid in tcl so I turned to
python in hope that this scripting language could do so.

The tcl solution spawns a new tcsh after setting several environment
variables and works quite well except for not being able to change
gid. And it is also a wish from my side to port this script to python.

Is your suggestion to put "newgrp design" into a new file and then
exec this file in my python script? What happens to the group id of
the shell that called the python script in this case? I would try to
avoid spawning a new tcsh as this make execution of tools on a remote
computer difficult as the handover of command line arguments does not
seem to be handed over to the newly spawned shell. I may be
understanding something wrongly here.

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


  1   2   >