Re: Unicode characters, XML/RSS

2008-07-31 Thread Stefan Behnel
Adam W. wrote:
   File C:\Python25\lib\xml\sax\expatreader.py, line 207, in feed
 self._parser.Parse(data, isFinal)
   File C:\Users\Adam\Desktop\Rev3 DL\XMLWorkspace.py, line 51, in
 characters
 self.data.append(string)
 UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in
 position 236: ordinal not in range(128)

You seem to be doing an implicit conversion from a unicode string to a byte
string, maybe by concatenating ('+' operator) strings of different types or by
writing it out into a file (or printing it, or ...) - I don't know what
self.data is or does, since you didn't provide any code.

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


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Russ P.
On Jul 30, 10:43 pm, Erik Max Francis [EMAIL PROTECTED] wrote:
 Russ P. wrote:
  On Jul 30, 9:27 pm, Erik Max Francis [EMAIL PROTECTED] wrote:
  You're sure going on about a distinction without a difference for a guy
  who childishly likes to call other people names.  A reasonable person
  would have long ago moved on instead of blaming others for not
  immediately intuiting your thoughts, rather than straightforwardly
  reading your words.  Which, by the way, includes at least three people
  other than myself.

  But I'll bet the mindless namecalling is really working out for you.
  Go, team, go!

  You earned the childish name calling by acting like a child -- with
  your petty little game of trying to show that I don't understand a
  basic concept in Python. As I said, your initial misunderstanding,
  while silly, was at least forgivable. But your insistence on repeating
  it time after time is not. It is truly pathetic.

 Sis, boom, rah rah rah!

 You're kind of skipping over the point where three other people had the
 same misunderstanding about your original statement and correction, so

Another whopper, but who's counting?

 maybe the reader is not the problem but rather the writer, but hey,
 don't let that get in the way of a good public shitfit.

 You're winning!

And you're a professional of some sort? Man, I can't even imagine
working in an environment with people like you. I guess I'm pretty
lucky to work with real professionals who don't play petty little
games like the one you played here -- and are still playing. Go ahead,
have the last word, loser -- then get lost.

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


Re: Python parsing iTunes XML/COM

2008-07-31 Thread Stefan Behnel
william tanksley wrote:
 william tanksley [EMAIL PROTECTED] wrote:
 I'm still puzzled why I'm getting some non-Unicode out of an
 ElementTree's text, though.
 
 Now I know.
 
 Okay, my answer is that cElementTree (in Python 2.5) is simply
 deranged when it comes to Unicode. It assumes everything's ASCII.

It does not assume that. It *requires* byte strings to be ASCII. If it
didn't enforce that, how could it possibly know what encoding they were using,
i.e. what they were supposed to mean at all? Read the Python Zen, in the face
of ambiguity, ElementTree refuses the temptation to guess. Python 2.x does
exactly the same thing when it comes to implicit conversion between encoded
strings and Unicode strings.

If you want to pass plain ASCII strings, you can either pass a byte string or
a Unicode string (that's a plain convenience feature). If you want to pass
anything that's not ASCII, you *must* pass a Unicode string.


 Reference: http://codespeak.net/lxml/compatibility.html
 
 (Note that the lxml version also doesn't handle Unicode correctly; it
 errors when XML declares its encoding.)

It definitely does handle Unicode correctly. Let me guess, you tried passing
XML as a Unicode string into the parser, and your XML declared itself as
having a byte encoding (?xml encoding=...?). How can that *not* be an error?


 This is unpleasant, but at least now I know WHY it was driving me
 insane.

You should *really* read a bit about Unicode and byte encodings. Not
understanding a topic is not a good excuse for complaining about it being
broken for you.

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


Re: interpreter vs. compiled

2008-07-31 Thread Tim Roberts
castironpi [EMAIL PROTECTED] wrote:

In C, we have:

int x, y;
x= 10;
y= x+ 1;

It translates as, roughly:

8000 .data
7996  #x
7992  #y
7988 .end data
7984 loadi reg0 7996
7980 loadi reg1 7992
7976 loadi reg2 10
7972 loadi reg3 1
7968 storv reg2 reg0
7964 add reg0 reg1 reg2
7960 storv reg3 reg1

I don't recognize that assembly language.  Is that another intermediate
language?

You are telling me that the same thing happens in IronPython. 

Yes, the same process happens.

By the
time the instruction pointer gets to 'x= 10', the next 7 instructions
are the ones shown here compiled from C.

I most certainly did NOT say that, as you well know.  Different C compilers
produce different instruction sequences for a given chunk of code.  Indeed,
a single C compiler will produce different instruction sequences based on
the different command-line options.  It's unreasonable to expect a Python
compiler to produce exactly the same code as a C compiler.

However, that does disqualify the Python processor as a compiler.

CMIIW, but the CPython implementation -does- -not-.

And again, I never said that it did.  CPython is an interpreter.  the
user's code is never translated into machine language.

My point is, CPython takes more than seven steps.  My question is,
does IronPython?

So, if compiler B isn't as good at optimization as compiler A, does that
mean in your mind that compiler B is not a compiler?
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza  Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Questions about asyncore

2008-07-31 Thread Frank Millman
On Jul 30, 7:50 pm, Giampaolo Rodola' [EMAIL PROTECTED] wrote:
 On 30 Lug, 09:49, Frank Millman [EMAIL PROTECTED] wrote:


Thanks again, Giampaolo, your input is really appreciated.


 I pretty much have the same overview I had before.
 As far as I can tell the only reason you want to use a thread is when
 you have to do something which requires a consistent amount of time to
 complete so that the asyncore loop gets blocked.
 The question is: is there anything like that in your code?
 If the answer is no then you don't need to use threads.
 Maybe you are just not used to the asynchronous approach where wait
 for server to respond or wait for the response to be complete
 doesn't mean that YOU have to wait.
 It means that when a specific condition occurs (e.g. some data is
 received) a certain method of the framework you're using will be
 called and then it will be up to you deciding what do to.

Maybe I am not being clear enough on my side.

I (hope I) understand the power of asnyc. I have written the server to
use async techniques, and when I get around to writing the full-blown
client, that will also use async techniques.

However, at this stage, all I want to do is write something quick and
dirty to check that the server is behaving as intended. I want to
throw some messages at it, more or less at random, and check the
responses. I found it much easier to do this with asyncore.loop
running in a separate thread.

To send a message from the main thread, I append it to a list called
self.sendData. In asyncore.dispatcher, writable() returns True if the
list contains anything, and handle_write() pops the message off the
list and sends it.

To receive messages, readable() always return True, and handle_read()
breaks up the input into individual messages and appends them to a
list called self.recvData. When the main thread is waiting for a
response, it simply loops until self.recvData contains something.

To do this asynchronously, for every test I would have to define the
detailed interaction between client and server, and write methods to
be called from within handle_read(). It could be done, but it would be
much more tedious.

Does this make sense?

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


Re: how to split text into lines?

2008-07-31 Thread Chris
On Jul 31, 7:26 am, alex23 [EMAIL PROTECTED] wrote:
 kj wrote:
  Sorry, I should have googled this first.  I just found splitlines()...

  Still, for my own edification, is there a way to achieve the same
  effect using re.split?

 re.split(os.linesep, string) works the same as string.splitlines()

 Neither retain the EOL for each line, though. The only way I'm aware
 of is to re-add it:

 [s+os.linesep for s in re.split(os.linesep, string)]

 Was that what you were after?

or what about 'string'.splitlines(True) as that retains newline
characters. ;)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie Python questions

2008-07-31 Thread Tim Roberts
LessPaul [EMAIL PROTECTED] wrote:

...My
question is in regard to GUI platforms. My primary target would be
Windows, but I would also like be able to support Linux and Mac
versions if possible. I'm also interested in using a system that also
has support for pure C++ applications. As such, and after reading many
web pages regarding Python GUIs, I believe I have the candidates
narrowed down to pyQT and wxPython.

The first question -- how steep is the curve to become proficient with
the above GUI packages?

There is so much personal preference here that it is extremely hard to give
any guidance.  If you have done any Windows programming at all, so that you
are familiar with the event-driven programming model, then I don't think
you would see that much difference in learning curve.  The two packages are
more alike than they are different -- the various APIs are just spelled
differently.

I happen to be a big wxPython fan.  I learn best by example, and wxPython
has a 44,000-line demo suite with 167 source files that demonstrates
virtually every class it includes.

Since there appears to be no commercial licencing fee for wxWidgets/
wxPython, the last question is what do I gain from going QT over wx?
I've seen great applications written with both (on my computer I have
the wxPython Digsby and the pyQT apps Mnemosyne and Anki. All seem
to be solid.

Yep.  Personal preference.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza  Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Optimizing size of very large dictionaries

2008-07-31 Thread Raymond Hettinger
  Are there any techniques I can use to strip a dictionary data
  structure down to the smallest memory overhead possible?

Sure.  You can build your own version of a dict using
UserDict.DictMixin.  The underlying structure can be as space
efficient as you want.

FWIW, dictionaries automatically become more space efficient at
largers sizes (50,000+ records).  The size quadrupling strategy falls
back to just doubling whenever a dict gets two thirds full.

  Background: I'm trying to identify duplicate records in very
  large text based transaction logs. I'm detecting duplicate
  records by creating a SHA1 checksum of each record and using this
  checksum as a dictionary key. This works great except for several
  files whose size is such that their associated checksum
  dictionaries are too big for my workstation's 2G of RAM.

Tons of memory can be saved by not storing the contents of the
record.  Just make an initial pass to identify the digest values of
possible duplicates.  The use a set to identify actual dups but only
store the records for those whose digest is a possible duplicate:

  bag = collections.defaultdict(int)
  for record in logs:
  bag[sha1(record).digest()] += 1
  possible_dups = set()
  while bag:
  hashval, cnt = bag.popitem()
  if cnt  1:
  possible_dups.add(hashvalue)
  seen = set()
  for record in logs:
  if record in seen:
  print 'Duplicate:', record
  elif sha1(record).digest() in possible_dups:
  seen.add(record)

Raymond

P.S.  If the log entries are one liners, maybe it would be better to
use the operating system's sort/uniq filters.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How can I check nbr of cores of computer?

2008-07-31 Thread Duncan Booth
Steven D'Aprano [EMAIL PROTECTED] wrote:

 I don't expect that Python will have a built-in core-counting function. 
 You would probably need to ask the operating system. On Linux, you could 
 do this:
 
 import os
 text = os.popen('cat /proc/cpuinfo').read()
 
 
 How you would do it in Windows or Mac, I have no idea.
 

One way on windows:

 import win32pdhutil
 def howmanycores():
for i in range():
try: win32pdhutil.GetPerformanceAttributes(Processor(%d) % i,% 
Processor Time)
except: break
return i

 print howmanycores()
2

-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: win32com ChartObject pythonwin vs idle

2008-07-31 Thread Tim Golden

sterling wrote:

I'm curious as to why the difference between IDLE and pythonWin when
using win32com.
opening an excel file, i've attempted to grab the chart information
out of the file.

commands like co = ChartObjects(1)  works in pythonWin but doesn't
work in IDLE.

however, on both co = chartobjects(1) works just fine.


I can't speak for IDLE vs PythonWin but in general
case-sensitivity of win32com stuff is related to
early vs late Dispatch. If you've explicitly generated
proxy modules for the Excel objects (via makepy,
EnsureDispatch or whatever) then those are Python
modules with case-sensitivity. If you're using dynamic
dispatch then Python is simply passing your attribute
name along to COM, which isn't case-sensitive, so either
case will work.

Not sure why IDLE vs PythonWin should make a difference
here, but maybe the above explanation sheds some light...

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


Re: New CMS in Python

2008-07-31 Thread Martin Sand Christensen
 :-)  [EMAIL PROTECTED] writes:

[...]
 Please send me how U expect your new CMS would be?

I don't mean to be disparaging, but I'd like to point out a few things
that I'm not entirely sure you've thought through.

Firstly, there is currently no shortage in CMS', and especially not in
half-completed, poorly thought out CMS' (not, of course, that I'm saying
yours is necessarily poorly thought out). Unless you bring some new
ideas to the playing field, or unless you think you can do something
better than the existing CMS' already do, the world isn't going to care
about your particular CMS. If you're writing your CMS for fun and
experience, that's great for you and probably a very good idea, but
don't expect many other people to show enthusiasm.

Secondly and related to my first point, if you're asking for people's
input on how they'd like your CMS to be, you've probably not given
purpose and design a lot of thought, and so I must reiterate that unless
you do something new or something better, don't expect anyone to care.
If you want to build a community around your project, the best thing to
do is generally to get something working on your own and then open up
for others when there's actually something to work on. And that means
that you should have a reasonably clear idea where you're going before
setting out.

Anyway, the best of luck to you!

-- 
Martin Sand Christensen
IT Services, Dept. of Electronic Systems
--
http://mail.python.org/mailman/listinfo/python-list


Re: Change PC to Win or Windows

2008-07-31 Thread Ross Ridge
Dennis Lee Bieber  [EMAIL PROTECTED] wrote:
   It gets even worse... No Windows-based PC has ever used the
PowerPC processor -- which had been a staple of the Macintosh before
they went Intel...

Actually the were personal computers sold using PowerPC processors that
ran Windows NT.  I even remember seeing one that had ISA slots.

Ross Ridge

-- 
 l/  //   Ross Ridge -- The Great HTMU
[oo][oo]  [EMAIL PROTECTED]
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //   
--
http://mail.python.org/mailman/listinfo/python-list


hosting on djangodomain.com

2008-07-31 Thread Łowik

Hi!
Did anyone used this hosting or heard about it? It's good or not?  what 
can you talk about it?

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


Re: Python parsing iTunes XML/COM

2008-07-31 Thread John Machin
On Jul 31, 12:58 am, william tanksley [EMAIL PROTECTED] wrote:
 Thank you for the response. Here's some more info, including a little
 that you didn't ask me for but which might be useful.

 John Machin [EMAIL PROTECTED] wrote:
  william tanksley [EMAIL PROTECTED] wrote:
   To ask another way: how do I convert from a file:// URL to a local
   path in a standard way, so that filepaths from two different sources
   will work the same way in a dictionary?
   The problems occur when the filenames have non-ascii characters in
   them -- I suspect that the URLs are having some encoding placed on
   them that Python's decoder doesn't know about.
  # track_id = url2pathname(urlparse(track_id).path)
  print repr(track_id)
  parse_result = urlparse(track_id).path
  print repr(parse_result)
  track_id_replacement = url2pathname(parse_result)
  print repr(track_id_replacement)

 The important value here is track_id_replacement; it contains the
 data that's throwing me. It appears that some UTF-8 characters are
 being read as multiple bytes by ElementTree rather than being decoded
 into Unicode.

Appearances can be deceptive. You present no evidence.

 Could this be a bug in ElementTree's Unicode support?

It could, yes, but the probability is extremely low.

 If
 so, can I work around it?

 Here's one example. The others are similar -- they have the same
 things that look like problems to me.

 Buffett Time - Annual Shareholders\xc2\xa0L.mp3

 Note some problems here:

Where?


 1. This isn't Unicode; it's missing the u (I printed using repr).
 2. It's got the UTF-8 bytes there in the middle.

 I tried doing track_id.encode(utf-8), but it doesn't seem to make
 any difference at all.

 Of course, my ultimate goal is to compare the track_id to the track_id
 I get from iTunes' COM interface, including hashing to the same value
 for dict lookups.

  and copy/paste the results into your next posting.

 In addition to the above results,

*WHAT* results? I don't see any repr() output, just your
interpretation of what you think you saw!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Possible to have multiple loop variables?

2008-07-31 Thread Alan Franzoni
laredotornado was kind enough to say:

 How would I set up the ms1 array such that I can use three items per
 object?

Use tuples. But that should depend on which values make up the key for your
mapping.

E.g.
ms1 = {('managed1':7019):8020, ('managed2':7020):8021}
ms2 = {'managed1':(7019:8020), 'managed2':(7020:8021)}

depending on what you want, and then iterate over such structure just like
Marc suggested.

Otherwise, you can create a custom class which returns three-tuples when
iterated, in such case you can just extract m, lp, ssl_lp in the for cycle
just like your example.



-- 
Alan Franzoni [EMAIL PROTECTED]
-
Remove .xyz from my email in order to contact me.
-
GPG Key Fingerprint:
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E
--
http://mail.python.org/mailman/listinfo/python-list


Re: interpreter vs. compiled

2008-07-31 Thread Bob Martin
in 76135 20080731 090911 Dennis Lee Bieber [EMAIL PROTECTED] wrote:
On Thu, 31 Jul 2008 06:17:59 GMT, Tim Roberts [EMAIL PROTECTED] declaimed
the following in comp.lang.python:


 And again, I never said that it did.  CPython is an interpreter.  the
 user's code is never translated into machine language.

Using that definition, the UCSD P-code Pascal and Java are also not
compilers -- all three create files containing instructions for a
non-hardware virtual machine.

The only difference between Python, UCSD Pascal, and Java is that
Python foregoes the explicit compiler pass.

BASIC (classical microcomputer implementations -- like the one M$
supplied for TRS-80s) is an interpreter -- the pre-scan of the source
merely translated BASIC keywords into a byte index, not into opcodes for
any virtual machine.

You are confusing languages with implementations, as I pointed out earlier.
Java is a language.  
I have used at least 2 Java compilers, ie they compiled Java source to native
machine language.
--
http://mail.python.org/mailman/listinfo/python-list


Re: interpreter vs. compiled

2008-07-31 Thread Duncan Booth
Terry Reedy [EMAIL PROTECTED] wrote:

 1. Portability: The Microsoft C# JIT compiler runs under Windows .NET
 on x86/amd64 and maybe it64 and what else?  Just porting .NET to run
 0n Linux on the same processors was/is a bit task.  Does MONO have a
 JIT also? 

Technically there is no such thing as a Microsoft C# JIT compiler: the C# 
compiler targets IL and the JIT compilers convert IL to the native machine,  
but C# is just one of the frontend compilers you could use.

Microsoft do JIT compilers for .Net Compact Framework that target ARM, 
MIPS, SHx and x86. The Mono JIT supports:

s390, s390x (32 and 64 bits) Linux
SPARC(32) Solaris, Linux
PowerPC Linux, Mac OSX
x86 Linux, FreeBSD, OpenBSD, NetBSD, Microsoft Windows, Solaris, OS X
x86-64: AMD64 and EM64T (64 bit) Linux, Solaris
IA64 Itanium2 (64 bit) Linux
ARM: little and big endian Linux (both the old and the new ABI)
Alpha Linux
MIPS Linux
HPPA Linux

(from http://www.mono-project.com/Supported_Platforms)


So I'd say .Net scores pretty highly on the portability stakes. (Although 
of course code written for .Net might not do so well).

-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Iain King
On Jul 31, 7:08 am, Russ P. [EMAIL PROTECTED] wrote:
 On Jul 30, 10:43 pm, Erik Max Francis [EMAIL PROTECTED] wrote:



  Russ P. wrote:
   On Jul 30, 9:27 pm, Erik Max Francis [EMAIL PROTECTED] wrote:
   You're sure going on about a distinction without a difference for a guy
   who childishly likes to call other people names.  A reasonable person
   would have long ago moved on instead of blaming others for not
   immediately intuiting your thoughts, rather than straightforwardly
   reading your words.  Which, by the way, includes at least three people
   other than myself.

   But I'll bet the mindless namecalling is really working out for you.
   Go, team, go!

   You earned the childish name calling by acting like a child -- with
   your petty little game of trying to show that I don't understand a
   basic concept in Python. As I said, your initial misunderstanding,
   while silly, was at least forgivable. But your insistence on repeating
   it time after time is not. It is truly pathetic.

  Sis, boom, rah rah rah!

  You're kind of skipping over the point where three other people had the
  same misunderstanding about your original statement and correction, so

 Another whopper, but who's counting?

  maybe the reader is not the problem but rather the writer, but hey,
  don't let that get in the way of a good public shitfit.

  You're winning!

 And you're a professional of some sort? Man, I can't even imagine
 working in an environment with people like you. I guess I'm pretty
 lucky to work with real professionals who don't play petty little
 games like the one you played here -- and are still playing. Go ahead,
 have the last word, loser -- then get lost.

You understand this is usenet, right?  Where we can all read the
entire thread?  So trying to spin the situation just doesn't work?
Just checking...

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


working pylint anyone?

2008-07-31 Thread Diez B. Roggisch
Hi,

until yesterday I was a happy user of pylint. Then I upgraded to ubuntu
hardy heron - and the trouble began.

The packaged version of pylint (0.13.2) fails with this error (last line):

logilab.common.configuration.UnsupportedAction: callback

The same error happens if I use 

easy_install-2.5
http://release.ingeniweb.com/third-party-dist/logilab.installer-0.1.tgz

as found on the net. Using easy_install pylint misses logilab-common 
astng, installing these additionally (easy_install) creates two eggs - but
unfortunately, the don't actually create a namespace-package logilab,
instead either one of them is picked up depending on installation order.

Then I tried the source releases - no luck either, either they produce the
same error or something similar.

I tried looking into the MLs - the last posts are from around 2006, so I
refrained from actually subscribing.

So - anybody out here having an actually working pylint config and can tell
me what versions work together? I've become pretty dependend on it to be
honest...

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


Re: working pylint anyone?

2008-07-31 Thread Stefan Rank

on 31.07.2008 11:29 Diez B. Roggisch said the following:
snip


The packaged version of pylint (0.13.2) fails with this error (last line):


snip


So - anybody out here having an actually working pylint config and can tell
me what versions work together? I've become pretty dependend on it to be
honest...


Three installations of pylint 0.14.0 that I have access to from here:

pylint.bat 0.14.0,
astng 0.17.2, common 0.27.0
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]

pylint 0.14.0,
astng 0.17.2, common 0.31.0
Python 2.5.2 (r252:60911, Jul 23 2008, 00:17:15)
[GCC 4.1.2 (Gentoo 4.1.2 p1.0.2)]

pylint 0.14.0,
astng 0.17.2, common 0.27.0
Python 2.5.1 (r251:54863, Jul 11 2007, 15:07:18)
[GCC 3.3.5 (Debian 1:3.3.5-13)]


All of them installed using good old setup.py (times 3).
easy_install does not work as you noted.

Hope that helps.
cheers,
stefan

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


Re: SVN access with pysvn under Cygwin (Installation problems)

2008-07-31 Thread Andy Dingley
On 30 Jul, 20:30, Jason Tishler [EMAIL PROTECTED] wrote:

 You need to build (and install) pysvn under Cygwin.  The pre-built
 Windows version will not work under Cygwin.

Thanks. Presumably this same problem would affect anything that uses
a .pyd under Cygwin?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Optimizing size of very large dictionaries

2008-07-31 Thread M.-A. Lemburg

On 2008-07-31 02:29, [EMAIL PROTECTED] wrote:

Are there any techniques I can use to strip a dictionary data
structure down to the smallest memory overhead possible?

I'm working on a project where my available RAM is limited to 2G
and I would like to use very large dictionaries vs. a traditional
database.

Background: I'm trying to identify duplicate records in very
large text based transaction logs. I'm detecting duplicate
records by creating a SHA1 checksum of each record and using this
checksum as a dictionary key. This works great except for several
files whose size is such that their associated checksum
dictionaries are too big for my workstation's 2G of RAM.


If you don't have a problem with taking a small performance hit,
then I'd suggest to have a look at mxBeeBase, which is an on-disk
dictionary implementation:

http://www.egenix.com/products/python/mxBase/mxBeeBase/

Of course, you could also use a database table for this. Together
with a proper index that should work as well (but it's likely slower
than mxBeeBase).

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jul 31 2008)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
--
http://mail.python.org/mailman/listinfo/python-list


Re: Interbase

2008-07-31 Thread M.-A. Lemburg

On 2008-07-30 18:49, Mike Hjorleifsson wrote:

Has anyone gotten python working with Interbase database platform ?  I
need to query some info from an interbase database on another server
need  a lil help getting started.


You could try the EasySoft ODBC driver for InterBase:

http://www.easysoft.com/products/data_access/odbc_interbase_driver/index.html

together with our mxODBC interface for Python:

http://www.egenix.com/products/python/mxODBC/

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jul 31 2008)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
--
http://mail.python.org/mailman/listinfo/python-list


Difference between type and class

2008-07-31 Thread Nikolaus Rath
Hello,

Can someone explain to me the difference between a type and a class?
After reading http://www.cafepy.com/article/python_types_and_objects/
it seems to me that classes and types are actually the same thing:

 - both are instances of a metaclass, and the same metaclass ('type')
   can instantiate both classes and types.
 - both can be instantiated and yield an ordinary object
 - I can even inherit from a type and get a class

So why does Python distinguish between e.g. the type 'int' and the
class 'myclass'? Why can't I say that 'int' is a class and 'myclass'
is a type?

I hope I have managed to get across the point of my confusion...


Thanks in advance,

   -Nikolaus

-- 
 »It is not worth an intelligent man's time to be in the majority.
  By definition, there are already enough people to do that.«
 -J.H. Hardy

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
--
http://mail.python.org/mailman/listinfo/python-list

Re: Is it possible to consume UTF8 XML documents using xml.dom.pulldom?

2008-07-31 Thread Paul Boddie
On 30 Jul, 20:15, Peter Otten [EMAIL PROTECTED] wrote:
 Paul Boddie wrote:
  Who wants to be first to submit a patch? ;-)

 And where? The sourceforge page says

 PyXML is no longer maintained.

The minidom code is in the standard library:

http://svn.python.org/view/python/trunk/Lib/xml/dom/

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


Re: ANN: Google custom search engine for Python

2008-07-31 Thread Gerard flanagan

Gerard flanagan wrote:

What is it?
---

A Google custom search engine which targets only the following sites:

+ `The Hazel Tree http://thehazeltree.org`__
+ `The Python standard library docs http://docs.python.org/lib`__
+ `The Python wiki http://wiki.python.org`__
+ `Python Package Index http://pypi.python.org/pypi`__

Where can I access it?
--

The home page of the search engine is here:

http://www.google.com/coop/cse?cx=002031040340806163079:nkigkp_irqk

As well as accessing it from its home page, you can link to it from your
own web sites, or add it as a gadget to your Google home page (if you 
have one) - see the above link for details.


No ads
--

`The Hazel Tree http://thehazeltree.org`__ is a not-for-profit site
and no ads will appear in the search results.

Using refinements
-

To refine the search to any of the individual sites, you can specify a
refinement using the following labels: stdlib, wiki, pypi, thehazeltree

So, to just search the python wiki, you would do:

   somesearchterm more:wiki

and similarly:

   somesearchterm more:stdlib
   somesearchterm more:pypi
   somesearchterm more:thehazeltree

About http://thehazeltree.org
-

`The Hazel Tree http://thehazeltree.org/`__ is a collection of popular
Python texts that I have converted to reStructuredText and put together
using `Sphinx http://sphinx.pocoo.org`__. It's in a publishable state,
but not as polished as I'd like, and since I'll be mostly offline for 
the next month it will have to remain as it is for the present. However, 
the search engine is ready now and the clock is ticking on its
subscription (one year, renewal depending on success of site), so if 
it's useful to anyone, it's all yours (and a link back to

http://thehazeltree.org would be appreciated).

Cheers,

G.

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



Added http://code.activestate.com/recipes/

(refinement name is `aspn`)

G.

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


Case tagging and python

2008-07-31 Thread Fred Mangusta

Hi,

I'm relatively new to programming in general, and totally new to python,
and I've been told that this language is particularly good for what I
need to do. Let me explain.
I have a large corpus of English text, in the form of several files.

First of all I would like to scan each file. Then, for each word I find,
I'd like to examine its case status, and write the (lower case) word back
to another text file - with, appended, a tag stating the case it had in 
the original file.


An example. Suppose we have three possible case conditions
-all lowercase
-all uppercase
-initial uppercase only

Three corresponding tags for each of these might be, respectively:
-nocap
-allcaps
-cap

Therefore, given the string

The Chairman of BP was asleep

I would like to produce

the/cap chairman/cap of/nocap /bp/allcaps was/nocap /asleep/nocap

and writing this into a file.


I have the following algorithm in mind:

-open input file
-open output file
-get line of text
-split line into words
-for each word
-tag = checkCase(word)
-newword = lowercase(word) + append(tag)
rejoin words into line
write line into output file

Now, I managed to write the following initial code

   for s in file:
lines += 1
if lines % 1000 == 0:
print '%d lines' % We print the total lines
sent = s.split() #split string by spaces
#...


But then I don't quite know what would be the fastest/best way to do 
this. Could I use the join function to reform the string? And, regarding 
the casetest() function, what do you suggest to do? Should I test each 
character of each word or there are faster methods?


Thanks very much,

F.



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


How smart is the Python interpreter?

2008-07-31 Thread ssecorp
def str_sort(string):
s = 
for a in sorted(string):
s+=a
return s


if i instead do:

def str_sort(string):
s = 
so = sorted(string)
for a in so:
s+=a
return s


will that be faster or the interpreter can figure out that it only has
to do sorted(string) once? or that kind of cleverness is usually
reserved for compilers and not interpreters?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Case tagging and python

2008-07-31 Thread bearophileHUGS
Fred Mangusta:
 Could I use the join function to reform the string?

You can write a function to split the words, for example taking in
account the points too, etc.


 And, regarding the casetest() function, what do you suggest to do?

Python strings have isupper, islower, istitle methods, they may be
enough for your purposes.


 -open input file
 -open output file
 -get line of text
 -split line into words
 -for each word
 -tag = checkCase(word)
 -newword = lowercase(word) + append(tag)
 rejoin words into line
 write line into output file

It seems good. To join the words of a line there's str.join. Now you
can write a function that splits lines, and another to check the case,
then you can show them to us.

Yet, I don't see how much use can have your output file :-)

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


Re: Tkinter- Possibly a basic question

2008-07-31 Thread joshdw4
On Jul 30, 6:48 pm, Guilherme Polo [EMAIL PROTECTED] wrote:
 On Wed, Jul 30, 2008 at 6:33 PM,  [EMAIL PROTECTED] wrote:
 ...

 ...

 The second option is to not create the root there, instead, make App
 inherit Tk. I rarely see people doing this, but it works too. Here you
 won't need to store the parent in an instance attribute, given it is
 always accessible through self.master since you are subclassing Tk.

 ...

 --
 -- Guilherme H. Polo Goncalves

Excellent, this one was easy enough for me to understand/implement and
it worked. Thanks for the help.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between type and class

2008-07-31 Thread oj
On Jul 31, 11:37 am, Nikolaus Rath [EMAIL PROTECTED] wrote:
 So why does Python distinguish between e.g. the type 'int' and the
 class 'myclass'? Why can't I say that 'int' is a class and 'myclass'
 is a type?

I might be wrong here, but I think the point is that there is no
distinction. A class (lets call it SomeClass for this example) is an
object of type 'type', and an instance of a class is an object of type
'SomeClass'.

So int is a type, but if you have an int variable, its type is int.

Same for your classes.

This is, ignoring old style classes. Make sure all your classes
inherit from object to get new style classes.
--
http://mail.python.org/mailman/listinfo/python-list


Re: How smart is the Python interpreter?

2008-07-31 Thread Ulrich Eckhardt
ssecorp wrote:
 def str_sort(string):
   s = 
   for a in sorted(string):
 s+=a
   return s
 
 
 if i instead do:
 
 def str_sort(string):
   s = 
   so = sorted(string)
   for a in so:
 s+=a
   return s
 
 will that be faster or the interpreter can figure out that it only has
 to do sorted(string) once?

Actually, by replacing sorted() with a function that outputs when it is
called you could have seen that this is only called once in both cases. It
must not be called more than once in fact, consider e.g. the case that it
introduces side effects (like e.g. reading a file).

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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

Re: Difference between type and class

2008-07-31 Thread Thomas Troeger

Can someone explain to me the difference between a type and a class?


If your confusion is of a more general nature I suggest reading the 
introduction of `Design Patterns' (ISBN-10: 0201633612), under 
`Specifying Object Interfaces'.


In short: A type denotes a certain interface, i.e. a set of signatures, 
whereas a class tells us how an object is implemented (like a 
blueprint). A class can have many types if it implements all their 
interfaces, and different classes can have the same type if they share a 
common interface. The following example should clarify matters:


class A:
def bar(self):
print A

class B:
def bar(self):
print B

class C:
def bla(self):
print C

def foo(x):
x.bar()

you can call foo with instances of both A and B, because both classes 
share a common type, namely the type that has a `bar' method), but not 
with an instance of C because it has no method `bar'. Btw, this example 
shows the use of duck typing (http://en.wikipedia.org/wiki/Duck_typing).


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


Re: working pylint anyone?

2008-07-31 Thread [EMAIL PROTECTED]
On Jul 31, 11:29 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 Hi,

 until yesterday I was a happy user of pylint. Then I upgraded to ubuntu
 hardy heron - and the trouble began.

 The packaged version of pylint (0.13.2) fails with this error (last line):

 logilab.common.configuration.UnsupportedAction: callback

This is a bug in the pylint package in Ubuntu, which has a wrong
versioned
dependency on python-logilab-common. You should report this bug to
ubuntu
using the reportbug command.

Which version of python-logilab-common and python-logilab-astng are
installed on your machine ?

 The same error happens if I use

 easy_install-2.5http://release.ingeniweb.com/third-party-dist/logilab.installer-0.1.tgz

 as found on the net. Using easy_install pylint misses logilab-common 
 astng, installing these additionally (easy_install) creates two eggs - but
 unfortunately, the don't actually create a namespace-package logilab,
 instead either one of them is picked up depending on installation order.

 Then I tried the source releases - no luck either, either they produce the
 same error or something similar.

You are probably picking up the system installation of logilab-common
when you
do this.

 I tried looking into the MLs - the last posts are from around 2006, so I
 refrained from actually subscribing.

I don't know where you checked, but there is some traffic on the
mailing list,
and questions generally get answered :-)

(http://lists.logilab.org/pipermail/python-projects/ is the correct
place)

 So - anybody out here having an actually working pylint config and can tell
 me what versions work together? I've become pretty dependend on it to be
 honest...

pylint 0.14.0 should work fine with logilab-common 0.33.0 and astng
0.17.2

Our Debian packages state that it should even work with logilab-common
= 0.22.0
and astng = 0.17.1 (although to be perfectly honnest, I'm not sure
that we have
tested pylint with logilab-common 0.22.0, so we could be the ones who
introduced
the bug in the Ubuntu package).

Hope this helps,

--
Alexandre Fayolle  LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian:  http://www.logilab.fr/formations
Développement logiciel sur mesure:   http://www.logilab.fr/services
Informatique scientifique:   http://www.logilab.fr/science

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


Re: How smart is the Python interpreter?

2008-07-31 Thread Heiko Wundram
Am Donnerstag, 31. Juli 2008 13:09:57 schrieb ssecorp:
 def str_sort(string):
   s = 
   for a in sorted(string):
   s+=a
   return s


 if i instead do:

 def str_sort(string):
   s = 
 so = sorted(string)
   for a in so:
   s+=a
   return s


 will that be faster or the interpreter can figure out that it only has
 to do sorted(string) once? or that kind of cleverness is usually
 reserved for compilers and not interpreters?

In a statement of the form

for name in iterable:

the expression iterable will only be evaluated once (to retrieve an 
iterator), so basically, both ways of stating it are equivalent and make 
negligible difference in runtime (the second version will be slower, because 
you have additional code to assign/fetch a local).

Anyway, if you care about speed, probably:

def str_sort(string):
return .join(sorted(string))

will be the fastest way of stating this.

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


Re: Terminate a python script from linux shell / bash script

2008-07-31 Thread Nigel Rantor

Gros Bedo wrote:

Thank you guys for your help. My problem is that I project to use this command 
to terminate a script when uninstalling the software, so I can't store the PID. 
This command will be integrated in the spec file of the RPM package. Here's the 
script I'll use, it may help someone else:

#!/bin/sh
# PYTHON SCRIPT PROCESS KILLER by GBO v0.1
# This script will look for all the lines containing $SOFTWARENAME in the 
process list, and close them

SOFTWARENAME='yoursoftware' #This is case insensitive
JOBPRESENT=$(ps -ef | grep -i $SOFTWARENAME | grep -v grep)
echo $JOBPRESENT
ps -ef | grep -i $SOFTWARENAME | grep -v grep | awk '{print $2}' | xargs kill


If you have a long running process you wish to be able to kill at a 
later date the normal way of doing it would be for the script itself to 
write it's own PID to a file that you can then inspect from a different 
process and use to kill it.


So, my_daemon.py might shove its PID into /var/run/my_daemon.pid

And later my_daemon_killer.py (or indeed my_daemon_killer.sh) would read 
the PID out of /var/run/my_daemon.pid and pass that to a kill command.


Using ps/grep in the way you're trying to do is always going to be 
inexact and people will not thank you for killing processes they wanted 
running.


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


Re: How smart is the Python interpreter?

2008-07-31 Thread Diez B. Roggisch
ssecorp wrote:

 def str_sort(string):
 s = 
 for a in sorted(string):
 s+=a
 return s
 
 
 if i instead do:
 
 def str_sort(string):
 s = 
 so = sorted(string)
 for a in so:
 s+=a
 return s
 
 
 will that be faster or the interpreter can figure out that it only has
 to do sorted(string) once? or that kind of cleverness is usually
 reserved for compilers and not interpreters?

There isn't much cleverness involved here - why on earth should one execute
the sorted(string) several times? 

The 

for name in iterable_yielding_expression

construct will evaluate the iterable_yielding_expression of course only
once.

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


Python Contractor needed

2008-07-31 Thread Rakesh Thakrar
Hi All,

 

An opportunity for a talented Python Software Engineer has arisen to
join a company which is currently going through a phase of rapid
expansion. Candidates must have excellent software development skills to
join an established team within this small company with offices in the
U.K. and U.S. An ideal candidate will be familiar with Linux, have a
passion for working with OpenSource software and a flair for creating
innovative solutions to complex problems.  

The candidate will be a self motivated, flexible software engineer
working within the existing I.T. Team. The day to day role will almost
exclusively focus on new projects.

Key elements of the role include

 

l  Work closely with the I.T. team and business managers to aid the
design and implementation of a new web based application for our
customers and data processing engine.

l  Work closely with the application design team to understand, agree,
plan and develop the new application.

l  Assess software requirements and assist with the project planning
stage.

l  Design, code and test various software elements in both Windows and
Linux based environments.

l  Ability to train and  mentor other members of the software
development team.

l  Experience of working within a development team using source control
and collaborative tools such as Subversion, CVS, Trac, etc.

l  Providing required documentation (specifications, test plans,
processes, etc).

 

This is a 6-12 month contract based near Portsmouth in Hampshire UK .

 

Please do not hesitate to contact me for further information.

 

Regards

Rakesh

 

___ 
Rakesh Thakrar
Manager
Microcom
Tel: 01923 851225
Mob: 079 7094 3227
Fax: 0845 389 2392
www.microcom-IT.com http://www.microcom-recruitment.com  
Beaumont Gate 

Shenley Hill

Radlett

Hertfordshire

WD7 7AR

  
Permanent and Contract IT Specialists 


 

P SAVE A TREE - PLEASE DO NOT PRINT THIS EMAIL UNLESS YOU REALLY NEED
TO.




The views expressed in this e-mail are not necessarily the views of
European Recruitment Network Ltd, its directors, officers or employees
make no representation or accept any liability for its accuracy or
completeness unless expressly stated to the contrary.
This e-mail, and any attachments are strictly confidential and intended
for the addressee(s) only.
The content may also contain legal, professional or other privileged
information. Unless expressly stated to the contrary, no contracts may
be concluded on behalf of European Recruitment Network Ltd by means of
e-mail communication. You may report the matter by calling us on 0845
389 2322.
Please ensure you have adequate virus protection before you open or
detach any documents from this transmission. European Network
Recruitment Ltd does not accept any liability for viruses. 
  
European Recruitment Network Ltd is registered in England: Company
Number: 5651508.
Registered Office: Greener House, 66-68 Haymarket, London, SW1Y 4RF 
  



 

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

Re: Continuous integration for Python projects

2008-07-31 Thread Leonid Shalupov

Hello,

Hussein B wrote:

Please correct my if I'm wrong but it seems to me that the major
continuous integration servers (Hudson, CruiseControl, TeamCity ..)
don't support Python based application.
It seems they mainly support Java, .NET and Ruby.
Can I use one of the previous listed servers for Python project?

You can use TeamCity.

Build and test your project with command-line runner and
make sure you've installed modules for reporting
tests to TeamCity.

http://www.jetbrains.net/confluence/display/TW/Python+Unit+Test+Reporting

--
Leonid.

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


Re: working pylint anyone?

2008-07-31 Thread Diez B. Roggisch
Stefan Rank wrote:

 on 31.07.2008 11:29 Diez B. Roggisch said the following:
 snip
 
 The packaged version of pylint (0.13.2) fails with this error (last
 line):
 
 snip
 
 So - anybody out here having an actually working pylint config and can
 tell me what versions work together? I've become pretty dependend on it
 to be honest...
 
 Three installations of pylint 0.14.0 that I have access to from here:
 
 pylint.bat 0.14.0,
 astng 0.17.2, common 0.27.0
 Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
 (Intel)]
 
 pylint 0.14.0,
 astng 0.17.2, common 0.31.0
 Python 2.5.2 (r252:60911, Jul 23 2008, 00:17:15)
 [GCC 4.1.2 (Gentoo 4.1.2 p1.0.2)]
 
 pylint 0.14.0,
 astng 0.17.2, common 0.27.0
 Python 2.5.1 (r251:54863, Jul 11 2007, 15:07:18)
 [GCC 3.3.5 (Debian 1:3.3.5-13)]
 
 
 All of them installed using good old setup.py (times 3).
 easy_install does not work as you noted.

Thanks, that helped. I got the same errors - but these are because of custom
init-hooks I created. Now I need to debug these.. thanks!

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


Re: SVN access with pysvn under Cygwin (Installation problems)

2008-07-31 Thread Jason Tishler
Andy,

On Thu, Jul 31, 2008 at 03:10:26AM -0700, Andy Dingley wrote:
 On 30 Jul, 20:30, Jason Tishler [EMAIL PROTECTED] wrote:
  You need to build (and install) pysvn under Cygwin. The pre-built
  Windows version will not work under Cygwin.
 
 Thanks. Presumably this same problem would affect anything that uses a
 .pyd under Cygwin?

Yes, Python shared extension modules are specific to the Python used to
build them.  This is the situation even though Windows Python and Cygwin
Python both run on the same operating system.

BTW, this is why I added shared extension module support to Cygwin
Python almost 8 years ago.

Jason

-- 
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D  8784 1AFD E4CC ECF4 8EF6
--
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between type and class

2008-07-31 Thread Nikolaus Rath
Thomas Troeger [EMAIL PROTECTED] writes:
 Can someone explain to me the difference between a type and a class?

 If your confusion is of a more general nature I suggest reading the
 introduction of `Design Patterns' (ISBN-10: 0201633612), under
 Specifying Object Interfaces'.

 In short: A type denotes a certain interface, i.e. a set of
 signatures, whereas a class tells us how an object is implemented
 (like a blueprint). A class can have many types if it implements all
 their interfaces, and different classes can have the same type if they
 share a common interface. The following example should clarify
 matters:

 class A:
   def bar(self):
   print A

 class B:
   def bar(self):
   print B

 class C:
   def bla(self):
   print C

 def foo(x):
   x.bar()

 you can call foo with instances of both A and B, because both classes
 share a common type, namely the type that has a `bar' method), but not
 with an instance of C because it has no method `bar'. Btw, this
 example shows the use of duck typing
 (http://en.wikipedia.org/wiki/Duck_typing).

That would imply that I cannot create instances of a type, only of
a class that implements the type, wouldn't it?

But Python denotes 'int' as a type *and* I can instantiate it.



Still confused,

   -Nikolaus

-- 
 »It is not worth an intelligent man's time to be in the majority.
  By definition, there are already enough people to do that.«
 -J.H. Hardy

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
--
http://mail.python.org/mailman/listinfo/python-list

Re: Difference between type and class

2008-07-31 Thread Nikolaus Rath
oj [EMAIL PROTECTED] writes:
 On Jul 31, 11:37 am, Nikolaus Rath [EMAIL PROTECTED] wrote:
 So why does Python distinguish between e.g. the type 'int' and the
 class 'myclass'? Why can't I say that 'int' is a class and 'myclass'
 is a type?

 I might be wrong here, but I think the point is that there is no
 distinction. A class (lets call it SomeClass for this example) is an
 object of type 'type', and an instance of a class is an object of type
 'SomeClass'.

But there seems to be a distinction:

 class int_class(object):
...   pass
... 
 int_class
class '__main__.int_class'
 int
type 'int'

why doesn't this print

 class int_class(object):
...   pass
... 
 int_class
type '__main__.int_class'
 int
type 'int'

or

 class int_class(object):
...   pass
... 
 int_class
class '__main__.int_class'
 int
class 'int'

If there is no distinction, how does the Python interpreter know when
to print 'class' and when to print 'type'?


Best,

   -Nikolaus

-- 
 »It is not worth an intelligent man's time to be in the majority.
  By definition, there are already enough people to do that.«
 -J.H. Hardy

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
--
http://mail.python.org/mailman/listinfo/python-list

Re: working pylint anyone?

2008-07-31 Thread Diez B. Roggisch
 Which version of python-logilab-common and python-logilab-astng are
 installed on your machine ?

By now, pylint 0.14 with logilab.common 0.27 and astng 0.17.2

I was able to track down the problem as being related to a custom init-hook.

See the attached .pylintrc + hook. They don't actually *do* anything (or,
the hook that is), but confuse pylint to spit out the reported error. Maybe
you can track down the real reason for the error?

 
 I don't know where you checked, but there is some traffic on the
 mailing list,
 and questions generally get answered :-)


On the website, I found this link:

http://www.logilab.org/mailinglist/850

through the search.


Diez
import sys

sys.path.apped(/home/dir)

[MASTER]
init-hook=execfile('/home/dir/.pylint_init_hook.py')
[VARIABLES]
dummy-variables-rgx=unused_|dummy|_
[MESSAGES CONTROL]
disable-msg=W0142,W0232,W0105,C0111,C0102,C0103,C0301


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

Re: Difference between type and class

2008-07-31 Thread Maric Michaud
Le Thursday 31 July 2008 14:30:19 Nikolaus Rath, vous avez écrit :
 oj [EMAIL PROTECTED] writes:
  On Jul 31, 11:37 am, Nikolaus Rath [EMAIL PROTECTED] wrote:
  So why does Python distinguish between e.g. the type 'int' and the
  class 'myclass'? Why can't I say that 'int' is a class and 'myclass'
  is a type?
 
  I might be wrong here, but I think the point is that there is no
  distinction. A class (lets call it SomeClass for this example) is an
  object of type 'type', and an instance of a class is an object of type
  'SomeClass'.

 But there seems to be a distinction:
  class int_class(object):

 ...   pass
 ...

  int_class

 class '__main__.int_class'

  int

 type 'int'

 why doesn't this print

  class int_class(object):

 ...   pass
 ...

  int_class

 type '__main__.int_class'

  int

 type 'int'

 or

  class int_class(object):

 ...   pass
 ...

  int_class

 class '__main__.int_class'

  int

 class 'int'

 If there is no distinction, how does the Python interpreter know when
 to print 'class' and when to print 'type'?


There are some confusion about the terms here.

Classes are instances of type 'type', but types are both instances and 
subclasses of 'type'. 
This recursivity is the base of the object model.

An instance of 'type' is a class (or a new type), but instances of a classes 
are not. 'type' is a metatype in term of OO.

What the type int means is that int is not a user type but a builtin type, 
instances of int are not types (or classes) but common objects, so its nature 
is the same as any classes.

The way it prints doesn't matter, it's just the __repr__ of any instance, and 
the default behavior for instances of type is to return 'class XX', but it 
can be easily customized.

[1]: class A(object) :
   ...: class __metaclass__(type) :
   ...: def __repr__(self) : return type A
   ...:
   ...:

[2]: A
...[2]: type A

[3]: type('toto', (object,), {})
...[3]: class '__main__.toto'



-- 
_

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

Re: working pylint anyone?

2008-07-31 Thread Mike Driscoll
On Jul 31, 4:29 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 Hi,

 until yesterday I was a happy user of pylint. Then I upgraded to ubuntu
 hardy heron - and the trouble began.

 The packaged version of pylint (0.13.2) fails with this error (last line):

 logilab.common.configuration.UnsupportedAction: callback

 The same error happens if I use

 easy_install-2.5http://release.ingeniweb.com/third-party-dist/logilab.installer-0.1.tgz

 as found on the net. Using easy_install pylint misses logilab-common 
 astng, installing these additionally (easy_install) creates two eggs - but
 unfortunately, the don't actually create a namespace-package logilab,
 instead either one of them is picked up depending on installation order.

 Then I tried the source releases - no luck either, either they produce the
 same error or something similar.

 I tried looking into the MLs - the last posts are from around 2006, so I
 refrained from actually subscribing.

 So - anybody out here having an actually working pylint config and can tell
 me what versions work together? I've become pretty dependend on it to be
 honest...

 Diez

For future reference, I found this installer package helpful in
getting PyLint and its dependencies to all install correctly:

http://tarekziade.wordpress.com/2008/02/20/pylint-installation-made-easier/
http://pypi.python.org/pypi/logilab.pylintinstaller

I used it on Windows, but it should (theoretically) work on Linux just
as well.

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


Re: Difference between type and class

2008-07-31 Thread Maric Michaud
Le Thursday 31 July 2008 13:32:39 Thomas Troeger, vous avez écrit :
 De :
 Thomas Troeger [EMAIL PROTECTED]  (Aioe.org NNTP Server)
   À :
 python-list@python.org
   Date :
 Aujourd'hui 13:32:39
    

  Can someone explain to me the difference between a type and a class?

 If your confusion is of a more general nature I suggest reading the
 introduction of `Design Patterns' (ISBN-10: 0201633612), under
 `Specifying Object Interfaces'.

 In short: A type denotes a certain interface, i.e. a set of signatures,
 whereas a class tells us how an object is implemented (like a
 blueprint). A class can have many types if it implements all their
 interfaces, and different classes can have the same type if they share a
 common interface. The following example should clarify matters:


Of course, this is what a type means in certain literature about OO 
(java-ish), but this absolutely not what type means in Python. Types are a 
family of object with a certain status, and they're type is type, 
conventionnaly named a metatype in standard OO.

There are three sort of objects in Python, in an inclusive order :

- ordinary object, or instance, they could not be instantiated or subclassed 
(in general), and are all an instance of type object (or a subclass of it).

- types, or classes, are all instance of type 'type' (or a subclass of it), 
they can be instantiated and they produce objects (ordinary object in 
general) with theirslef as a type.

- metatypes or metaclass, are subclasses of type, their instances are new 
types.

For all tjis work together you must admit the following recursivity :

'type' is both a subclass and an instance of 'object' while 'object' is an 
instance of 'type'. 

-- 
_

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


Re: Difference between type and class

2008-07-31 Thread Thomas Troeger

That would imply that I cannot create instances of a type, only of
a class that implements the type, wouldn't it?

But Python denotes 'int' as a type *and* I can instantiate it.


Now I start getting confused also ;-)

 a=5
 a.__class__
type 'int'
 a.__class__.__class__
type 'type'
 dir(a)
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', 
'__delattr__', '__div__', '__divmod__', '__doc__', '__float__', 
'__floordiv__', '__getattribute__', '__getnewargs__', '__hash__', 
'__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', 
'__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', 
'__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', 
'__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', 
'__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', 
'__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', 
'__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__']


I think in Python everything is implemented as a class which makes 
sense. AFAIK you can implement a certain interface in a custom class and 
it behaves like, for example, a builtin integer. But I guess one of the 
gurus can clarify this matter with an appropriate URL ;-)

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


current week / weeks in year - best practice

2008-07-31 Thread Aljosa Mohorovic
i use this to find out current week and total number of weeks for
current year:
now = datetime.now()
weeks_in_year = int(date(now.year, 12, 31).strftime(%W))
current_week = int(date(now.year, now.month, now.day).strftime(%W))

is this the best way or is there a better way?

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


problem when reading file

2008-07-31 Thread shrimpy
hi every one, i am new to python,
and coz i want to write a handy command for my linux machine, to find
a word in all the files which are under the current folder.

the code is half done, but when i run it, it complain, and i don`t know why???

can anyone help me have a look at it?


here is the message it complain
===
file is : qt_plugins_3.3rc

Traceback (most recent call last):
  File ./python_script/svn_grep.py, line 34, in module
searPatten(file,'are','no')
  File ./python_script/svn_grep.py, line 8, in searPatten
openFile = open(file, 'r')
IOError: [Errno 2] No such file or directory: 'qt_plugins_3.3rc'


here are the code i wrote
---code begin
#!/usr/bin/python

import os
import string


def searPatten(file, patten, isCaseSensitive):
openFile = open(file, 'r')
lines = openFile.readlines()
lineNum = 1
for text in lines :
words = text.split()
existed = 0
for word in words :
if isCaseSensitive == 'yes' :
if word.lower() == patten.lower():
existed = 1
break
else:
if word == patten :
existed = 1
break
if existed == 1:
print line :  + str(lineNum) +   + text
lineNum += 1
openFile.close()



for root, dirs, files in os.walk(os.getcwd()):
for file in files:
print ===
print file is :  + file + \n
searPatten(file,'are','no')

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


Re: Python parsing iTunes XML/COM

2008-07-31 Thread william tanksley
Stefan Behnel [EMAIL PROTECTED] wrote:
 william tanksley wrote:
  Okay, my answer is that ElementTree (in Python 2.5) is simply
  deranged when it comes to Unicode. It assumes everything's ASCII.

 It does not assume that. It *requires* byte strings to be ASCII.

You can't encode Unicode into an ASCII string. (Well, except using
UTF-7.) Bad requirement.

 If it
 didn't enforce that, how could it possibly know what encoding they were using,
 i.e. what they were supposed to mean at all? Read the Python Zen, in the face
 of ambiguity, ElementTree refuses the temptation to guess. Python 2.x does
 exactly the same thing when it comes to implicit conversion between encoded
 strings and Unicode strings.

An XML file that begins with the string ?xml encoding=utf-8? is
NOT ascii. You don't have to guess what encoding it's in. It's UTF-8.
If you error out when you hit an 8-bit character, you're not going to
be able to process that file. I'm completely lost on why you're
claiming otherwise.

Furthermore, when ElementTree returns (from one of its .text elements)
a string-of-bytes instead of a decoded Unicode string, it doesn't
merely resist the temptation to guess; instead, it forces ME to
guess. I've now had to hardcode utf-8 into my program, when IT just
bypassed and ignored an explicit instruction to use UTF-8. I hope and
assume that iTunes will never switch from UTF-8 to UTF-32 -- if it
does, my code breaks, and I'll probably have to switch away from
ElementTree (I guess that since it requires ASCII it won't even
pretend to handle more than 8 bits per character).

 If you want to pass plain ASCII strings, you can either pass a byte string or
 a Unicode string (that's a plain convenience feature). If you want to pass
 anything that's not ASCII, you *must* pass a Unicode string.

I don't care about strings. I've never passed ElementTree a string.
I'm using a file, a file that's correctly encoded as UTF-8, and it
returns some text elements that are raw bytes (undecoded). I have to
manually decode them.

  Reference:http://codespeak.net/lxml/compatibility.html

  (Note that the lxml version also doesn't handle Unicode correctly; it
  errors when XML declares its encoding.)

 It definitely does handle Unicode correctly.

Actually, this is my bad -- I misread the webpage. lxml appears to
handle unicode strings with a declared encoding correctly: it errors
out. That's quite reasonable when confronted with a contradiction.
According to that page, however, the standard ElementTree library
doesn't work that way -- it simply assumes that byte strings are
ASCII.

I'm going to back down on this one, though. I realize that this is a
single paragraph on a third-party website, and it's not really trying
to document the official ElementTree (it's trying to document its own
version, lxml). So it might not be correct, or it might be overly
ambiguous. It might also be talking ONLY about strings, to the
exclusion of file input. I don't know, and I don't have the energy to
debug it, especially since I can't fix anything about it even if
something was wrong :-).

So I revert to my former position: I don't know why those two lines
have to be in that order for my code to work correctly; I don't even
know why the encode line has to be there at all. When I was using
the old Python XML library, I didn't have to worry about encoding or
decoding; everything just worked. I really prefer ElementTree, and I'm
glad I upgraded, but it really looks like encoding is a problem.

 Let me guess, you tried passing
 XML as a Unicode string into the parser, and your XML declared itself as
 having a byte encoding (?xml encoding=...?). How can that *not* be an 
 error?

I thought you just said resist the temptation to guess? I didn't
pass a string. I passed a file. It didn't error out; instead, it
produced bytestring-encoded output (not Unicode).

 Stefan

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


Python Contractor needed

2008-07-31 Thread Rakesh Thakrar
Hi All,

 

An opportunity for a talented Python Software Engineer has arisen to
join a company which is currently going through a phase of rapid
expansion. Candidates must have excellent software development skills to
join an established team within this small company with offices in the
U.K. and U.S. An ideal candidate will be familiar with Linux, have a
passion for working with OpenSource software and a flair for creating
innovative solutions to complex problems.  

The candidate will be a self motivated, flexible software engineer
working within the existing I.T. Team. The day to day role will almost
exclusively focus on new projects.

Key elements of the role include

 

l  Work closely with the I.T. team and business managers to aid the
design and implementation of a new web based application for our
customers and data processing engine.

l  Work closely with the application design team to understand, agree,
plan and develop the new application.

l  Assess software requirements and assist with the project planning
stage.

l  Design, code and test various software elements in both Windows and
Linux based environments.

l  Ability to train and  mentor other members of the software
development team.

l  Experience of working within a development team using source control
and collaborative tools such as Subversion, CVS, Trac, etc.

l  Providing required documentation (specifications, test plans,
processes, etc).

 

This is a 6-12 month contract based near Portsmouth in Hampshire UK .

 

Please do not hesitate to contact me for further information.

 

Regards

Rakesh

 

___ 
Rakesh Thakrar
Manager
Microcom
Tel: 01923 851225
Mob: 079 7094 3227
Fax: 0845 389 2392
www.microcom-IT.com http://www.microcom-recruitment.com  
Beaumont Gate 

Shenley Hill

Radlett

Hertfordshire

WD7 7AR

  
Permanent and Contract IT Specialists 


 

P SAVE A TREE - PLEASE DO NOT PRINT THIS EMAIL UNLESS YOU REALLY NEED
TO.




The views expressed in this e-mail are not necessarily the views of
European Recruitment Network Ltd, its directors, officers or employees
make no representation or accept any liability for its accuracy or
completeness unless expressly stated to the contrary.
This e-mail, and any attachments are strictly confidential and intended
for the addressee(s) only.
The content may also contain legal, professional or other privileged
information. Unless expressly stated to the contrary, no contracts may
be concluded on behalf of European Recruitment Network Ltd by means of
e-mail communication. You may report the matter by calling us on 0845
389 2322.
Please ensure you have adequate virus protection before you open or
detach any documents from this transmission. European Network
Recruitment Ltd does not accept any liability for viruses. 
  
European Recruitment Network Ltd is registered in England: Company
Number: 5651508.
Registered Office: Greener House, 66-68 Haymarket, London, SW1Y 4RF 
  



 

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

Re: problem when reading file

2008-07-31 Thread Heiko Wundram
Am Donnerstag, 31. Juli 2008 15:44:33 schrieb shrimpy:
 hi every one, i am new to python,
 and coz i want to write a handy command for my linux machine, to find
 a word in all the files which are under the current folder.

What about

grep -R myword .

? Even works on regular expression (with e/fgrep). Type

grep --help

to see all the options you get (context display, ignoring anything that's not 
a proper file or directory, only printing filenames with matches, not the 
matches themselves, etc.).

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


Function References

2008-07-31 Thread [EMAIL PROTECTED]
Greetings,

I'm trying to wrap a function in a C library as a compiled C Python
module. Everything is going great, but I've hit a snag. There's a
function in the form of this:

First the typedef:
typedef void(*FPtr_DeviceMessageHandler) (const DeviceMessage, const
char*);

Then the actual function prototype:
FPtr_DeviceMessageHandler
RegisterDeviceMessageHandler(FPtr_DeviceMessageHandler);

Whenever this USB device I'm using generates a message, it's then sent
to that function whose reference you passed to
RegisterDeviceMessageHandler(). Here's an example:

void testfunc() {
  printf(test);
}
...on to main()
RegisterDeviceMessageHandler(testfunc)

So I've defined a similar function on my C module to do just this,
using the passed function reference to allow the device to send
messages to a Python function of the user's choice. I'm just not sure
how to do this, and the tutorials I've been digging through don't
offer any help. I've found some functions that look promising, but
can't figure out how to cast the function reference from Python into
something the C RegisterDevice... function can handle. Here's what
I've got:

static PyObject *
Py1_RegisterDeviceMessageHandler(PyObject *self, PyObject *args)
{
PyObject *handle, *parsed;

if(!PyArg_ParseTuple(args, O, handle)) {
return NULL;
}

parsed = PyMethod_Function(handle);
I1_RegisterDeviceMessageHandler(PyMethod_Function(handle));

Py_RETURN_TRUE;
} // end Py1_RegisterDeviceMessageHandler()

This fails since  PyMethod_Function returns a PyObject. Is there a way
to cast this to something generic? Casting to (void*) didn't seem to
work.

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


Re: Python parsing iTunes XML/COM

2008-07-31 Thread william tanksley
John Machin [EMAIL PROTECTED] wrote:
 william tanksley [EMAIL PROTECTED] wrote:
  Buffett Time - Annual Shareholders\xc2\xa0L.mp3
  1. This isn't Unicode; it's missing the u (I printed using repr).
  2. It's got the UTF-8 bytes there in the middle.
  In addition to the above results,

 *WHAT* results? I don't see any repr() output, just your
 interpretation of what you think you saw!

That *is* the repr. I said it's the repr, and it IS. It's not an
interpretation; it's a screenscrape. Really, truly. If I paste it in
again it'll look the same.

What do you want? Can I post something that will convince you it's a
repr?

Oh well. You guys have been immensely helpful; my mental model of how
Python works was vastly backwards, so it's a relief to get it
corrected. Thanks to that, I was able to hack my code into working. I
wish I could get entirely correct behavior, but at this point the
miscommunication is too strong. I'll settle for the hack I've got now,
and hope iTunes doesn't ever change its XML encoding (hey, I think
I've got cause to be optimistic).

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


Debugging of a long running process under Windows

2008-07-31 Thread Propad
Hello,
I know this issue pops up once in a while, but I haven't found a good
answer to it. I need to debug a long running application under
windows. The application is a combined java/python framework for
testing ECUs in the automotive industry. Basically, the Java GUI
(Eclipse-based) starts test-cases written in Python and provides the
console where the test-logs are seen. When there is a exception
somewhere in the testcases (or the underlying functionallity, also
written in Python), those are also logged, and then the framework
usually continues with the next command in the same test case.
I'd like to have a debugging facillity better than print statements. I
imagine:
a) something like a debugger poping up when I get an exception, or b)
something debugger-like poping up when it reaches a command I entered
something in the code,
or c) Me pressing on a button and getting a debugger-like-thing that
lets me look into the running, possibly halted code.
I've done some little experiments with the code module, which looks
nice but does not seem to get over the control from the java-part, and
with popen2(cmd), which seems not even to work if I start the code
from a dosbox (the same console is keept), and same thing when strated
by the Java-App.
Just to add, using pdb (or pythonwin debugger) seems not to be an
option, as it makes the test-runs much slower.
Does somebody have an idea? It seems there used to be a python
debugger called Pygdb, able to attach to a running application, but
now it seems it disapeared (now there is a python debugger with the
same name, linked to ViM).
Thanx,
Propad
--
http://mail.python.org/mailman/listinfo/python-list


Re: current week / weeks in year - best practice

2008-07-31 Thread Diez B. Roggisch
Aljosa Mohorovic wrote:

 i use this to find out current week and total number of weeks for
 current year:
 now = datetime.now()
 weeks_in_year = int(date(now.year, 12, 31).strftime(%W))
 current_week = int(date(now.year, now.month, now.day).strftime(%W))
 
 is this the best way or is there a better way?

Instead of datetime.now() use date.today(), which removes a lot of
boilerplate.

int(date.today().strftime(%W))

Apart from that, I think it's the way to go.

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


Re: Function References

2008-07-31 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

 Greetings,
 
 I'm trying to wrap a function in a C library as a compiled C Python
 module. Everything is going great, but I've hit a snag. There's a
 function in the form of this:
 
 First the typedef:
 typedef void(*FPtr_DeviceMessageHandler) (const DeviceMessage, const
 char*);
 
 Then the actual function prototype:
 FPtr_DeviceMessageHandler
 RegisterDeviceMessageHandler(FPtr_DeviceMessageHandler);
 
 Whenever this USB device I'm using generates a message, it's then sent
 to that function whose reference you passed to
 RegisterDeviceMessageHandler(). Here's an example:
 
 void testfunc() {
   printf(test);
 }
 ...on to main()
 RegisterDeviceMessageHandler(testfunc)
 
 So I've defined a similar function on my C module to do just this,
 using the passed function reference to allow the device to send
 messages to a Python function of the user's choice. I'm just not sure
 how to do this, and the tutorials I've been digging through don't
 offer any help. I've found some functions that look promising, but
 can't figure out how to cast the function reference from Python into
 something the C RegisterDevice... function can handle. Here's what
 I've got:
 
 static PyObject *
 Py1_RegisterDeviceMessageHandler(PyObject *self, PyObject *args)
 {
 PyObject *handle, *parsed;
 
 if(!PyArg_ParseTuple(args, O, handle)) {
 return NULL;
 }
 
 parsed = PyMethod_Function(handle);
 I1_RegisterDeviceMessageHandler(PyMethod_Function(handle));
 
 Py_RETURN_TRUE;
 } // end Py1_RegisterDeviceMessageHandler()
 
 This fails since  PyMethod_Function returns a PyObject. Is there a way
 to cast this to something generic? Casting to (void*) didn't seem to
 work.
 
 Thanks in advance!

May I suggest you move to ctypes for wrapping? It's easier, pure python and
callbacks are already built-in.

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


Re: Function References

2008-07-31 Thread [EMAIL PROTECTED]
Hello Diez.

 May I suggest you move to ctypes for wrapping? It's easier, pure python and
 callbacks are already built-in.

I'm pretty new to extending Python in C, I don't understand what
you're saying. Are there any examples or a brief explanation/URL you
could point me to?

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


Re: Function References

2008-07-31 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

 Hello Diez.
 
 May I suggest you move to ctypes for wrapping? It's easier, pure python
 and callbacks are already built-in.
 
 I'm pretty new to extending Python in C, I don't understand what
 you're saying. Are there any examples or a brief explanation/URL you
 could point me to?

Is google dead today?

http://www.google.com/search?q=python+ctypesie=UTF-8oe=UTF-8

First hit.

Ctypes is a since python2.5 built-in module that allows to declare
interfaces to C-libraries in pure python. You declare datatypes and
function prototypes, load a DLL/SO and then happily work with it. No C, no
compiler, no refcounts, no nothing.

And you can pass python-functions as callbacks.

See the module docs for examples.

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


Re: working pylint anyone?

2008-07-31 Thread [EMAIL PROTECTED]
On Jul 31, 2:39 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
  Which version of python-logilab-common and python-logilab-astng are
  installed on your machine ?

 By now, pylint 0.14 with logilab.common 0.27 and astng 0.17.2

 I was able to track down the problem as being related to a custom init-hook.

 See the attached .pylintrc + hook. They don't actually *do* anything (or,
 the hook that is), but confuse pylint to spit out the reported error. Maybe
 you can track down the real reason for the error?

Congratulation ! you've found a pylint bug (or more likely a logilab-
common bug
in our wrapper of optparse/optik) :-/

I have added it to our tracker (http://www.logilab.org/ticket/5677)
and it
should be fixed in the next release of pylint or logilab-common.

  I don't know where you checked, but there is some traffic on the
  mailing list,
  and questions generally get answered :-)

 On the website, I found this link:

 http://www.logilab.org/mailinglist/850

 through the search.

Ouch, this is actually a nasty bug on our site. I'm going to see what
I can do about it. In the meantime, you may consider subscribing
directly from http://lists.logilab.org/mailman/listinfo/python-projects

--
Alexandre Fayolle  LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian:  http://www.logilab.fr/formations
Développement logiciel sur mesure:   http://www.logilab.fr/services
Informatique scientifique:   http://www.logilab.fr/science
--
http://mail.python.org/mailman/listinfo/python-list


Re: Function References

2008-07-31 Thread [EMAIL PROTECTED]
 Ctypes is a since python2.5 built-in module that allows to declare
 interfaces to C-libraries in pure python. You declare datatypes and
 function prototypes, load a DLL/SO and then happily work with it. No C, no
 compiler, no refcounts, no nothing.

 And you can pass python-functions as callbacks.

The first sentence (and some really crummy licensing restrictions
imposed by the library distributor) alone here excludes this as a
valid option for this particular case, I definitely need Python 2.4
support.

So the question comes back around to being how is this same desired
behavior duplicated in the Python/C API?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Need help in writing up a Python Syntax checker

2008-07-31 Thread [EMAIL PROTECTED]
On Jul 14, 8:22 am, Kinokunya [EMAIL PROTECTED] wrote:
 Hi guys,

 My group and I will be working on our final year project, the scope to
 do a program/web-based application similar areas of functionalities
 like thePyLintand PyChecker; a Python syntax checker. We have no
 Python background, equipped only with some knowledge of Java and Dot
 net.

Great, this means you'll get a change to learn a new great language.

 We did some research on PyLint and found out that there are 2 common
 modules thatPyLint  PyChecker are using, namely logilab-astng and
 logilab-common. I'm not really sure what these 2 modules are for.

To my best knowledge, pychecker does not use logilab-common or logilab-
astng.

 Quoted from the offical site,

     The aim of this module (logilab-astng) is to provide a common base
 representation of python source code

 We're not really sure what they meant by common base representation of
 source codes. Does that mean logilab-astng is somewhat like a
 repository/library of Python syntax API so that we can easily 'call'
 these module to aid in syntax checking?

logilab-astng is a python library which gives access to the Abstract
Syntax
Tree (AST) of some Python code. This representation is used by pylint
to
perform checks on the code without manipulating the source code
directly.

 Our current stand was to use Jython as it is able to support Java as
 well as the .PY files inside logilab-astng and logilab-common, but
 having no knowledge in Python, we're unable to make out whatever was
 in the 2 above modules, was was unable to find user support forums/
 communities for Logilab related stuff.

Subscribe to the python-projects mailing list
(http://lists.logilab.org/mailman/listinfo/python-projects)

--
Alexandre Fayolle
Logilab
--
http://mail.python.org/mailman/listinfo/python-list


Re: Function References

2008-07-31 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

 Ctypes is a since python2.5 built-in module that allows to declare
 interfaces to C-libraries in pure python. You declare datatypes and
 function prototypes, load a DLL/SO and then happily work with it. No C,
 no compiler, no refcounts, no nothing.

 And you can pass python-functions as callbacks.
 
 The first sentence (and some really crummy licensing restrictions
 imposed by the library distributor) alone here excludes this as a
 valid option for this particular case, I definitely need Python 2.4
 support.

How much more liberal can it get than MIT-licensed? 


to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:


But then, if you insist, go down the hard road.

Diez

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


Re: Function References

2008-07-31 Thread Diez B. Roggisch
Diez B. Roggisch wrote:

 [EMAIL PROTECTED] wrote:
 
 Ctypes is a since python2.5 built-in module that allows to declare
 interfaces to C-libraries in pure python. You declare datatypes and
 function prototypes, load a DLL/SO and then happily work with it. No C,
 no compiler, no refcounts, no nothing.

 And you can pass python-functions as callbacks.
 
 The first sentence (and some really crummy licensing restrictions
 imposed by the library distributor) alone here excludes this as a
 valid option for this particular case, I definitely need Python 2.4
 support.
 
 How much more liberal can it get than MIT-licensed?
 
 
 to deal in the Software without restriction, including
 without limitation the rights to use, copy, modify, merge, publish,
 distribute, sublicense, and/or sell copies of the Software, and to
 permit persons to whom the Software is furnished to do so, subject to
 the following conditions:
 

Sorry, missed the paragraph


The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.


Still, AFAIK MIT is pretty liberal.

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


Re: Function References

2008-07-31 Thread [EMAIL PROTECTED]
 How much more liberal can it get than MIT-licensed?

Again, the licensing issue is everything to do with the original
library distributor, NOT ctypes.

 But then, if you insist, go down the hard road.

Irrelevant and unnecessary. If you don't want to help, don't please
don't reply.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between type and class

2008-07-31 Thread Nikolaus Rath
Maric Michaud [EMAIL PROTECTED] writes:
  Can someone explain to me the difference between a type and a class?

 If your confusion is of a more general nature I suggest reading the
 introduction of `Design Patterns' (ISBN-10: 0201633612), under
 `Specifying Object Interfaces'.

 In short: A type denotes a certain interface, i.e. a set of signatures,
 whereas a class tells us how an object is implemented (like a
 blueprint). A class can have many types if it implements all their
 interfaces, and different classes can have the same type if they share a
 common interface. The following example should clarify matters:


 Of course, this is what a type means in certain literature about OO
 (java-ish), but this absolutely not what type means in Python. Types
 are a family of object with a certain status, and they're type is
 type, conventionnaly named a metatype in standard OO.
[...]

Hmm. Now you have said a lot about Python objects and their type, but
you still haven't said what a type actually is (in Python) and in what
way it is different from a class. Or did I miss something?


Best,

   -Nikolaus

-- 
 »It is not worth an intelligent man's time to be in the majority.
  By definition, there are already enough people to do that.«
 -J.H. Hardy

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
--
http://mail.python.org/mailman/listinfo/python-list

Re: Function References

2008-07-31 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

 How much more liberal can it get than MIT-licensed?
 
 Again, the licensing issue is everything to do with the original
 library distributor, NOT ctypes.

I read library distributor as ctypes-library distributor because it is
3rd-party under 2.4. Which was the reason I quotet it's MIT-license.

And it escapes me what accessing the lib from ctypes is any different than
from your own compiled code. 
 
 But then, if you insist, go down the hard road.
 
 Irrelevant and unnecessary. If you don't want to help, don't please
 don't reply.

I take the freedom to do so as I see fit - this is usenet... 

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


HELP - Attribute Error, no matter what I do on PAMIE...

2008-07-31 Thread frankrentef
Greetings all. I'm new to PAMIE and I've watched / followed to PAMIE
videos on Show me Do. I've tried to duplicate the scriptWrite
function in an attempt to automate the forms process... without
success.

Can someone PLEASE Assist!?

I'm using the following code

from cPAMIE import PAMIE


#Imports - used to setup / control finding files
import time
import os
import sys
import cReport
#import elementtree.ElementTree as ET

#Create New Pamie Object
ie=PAMIE()
ie=Visible =1
t=time

ie=PAMIE ()

ie.navigate ('http://bir1edptest2/iswebcommander/fi/default.aspx')
ie.scriptWrite()


And getting the following error

Atribute Error:unknown.nameProp
File C:\PYCODE\scriptWrite TEST.py, line 19, in ?
ie.scriptWrite()
File C:\Python24\Lib\site-packages\cPAMIE.py, line 1837, in
scriptWrite
nameProp = getattr(x,nameProp)
File C:\Python24\Lib\site-packages\win32com\client\dynamic.py, line
496, in __getattr__
raise AttributeError, %s.%s % (self._username_, attr)

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


Re: Difference between type and class

2008-07-31 Thread Maric Michaud
Le Thursday 31 July 2008 16:46:28 Nikolaus Rath, vous avez écrit :
 Maric Michaud [EMAIL PROTECTED] writes:
   Can someone explain to me the difference between a type and a class?
 
  If your confusion is of a more general nature I suggest reading the
  introduction of `Design Patterns' (ISBN-10: 0201633612), under
  `Specifying Object Interfaces'.
 
  In short: A type denotes a certain interface, i.e. a set of signatures,
  whereas a class tells us how an object is implemented (like a
  blueprint). A class can have many types if it implements all their
  interfaces, and different classes can have the same type if they share a
  common interface. The following example should clarify matters:
 
  Of course, this is what a type means in certain literature about OO
  (java-ish), but this absolutely not what type means in Python. Types
  are a family of object with a certain status, and they're type is
  type, conventionnaly named a metatype in standard OO.

 [...]

 Hmm. Now you have said a lot about Python objects and their type, but
 you still haven't said what a type actually is (in Python) and in what
 way it is different from a class. Or did I miss something?

This paragraph ?


- types, or classes, are all instance of type 'type' (or a subclass of it), 
they can be instantiated and they produce objects (ordinary object in 
general) with theirslef as a type.


Maybe it's still unclear that types and classes *are* synonyms in Python.

-- 
_

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

Re: Difference between type and class

2008-07-31 Thread Nikolaus Rath
Maric Michaud [EMAIL PROTECTED] writes:
 Le Thursday 31 July 2008 14:30:19 Nikolaus Rath, vous avez écrit :
 oj [EMAIL PROTECTED] writes:
  On Jul 31, 11:37 am, Nikolaus Rath [EMAIL PROTECTED] wrote:
  So why does Python distinguish between e.g. the type 'int' and the
  class 'myclass'? Why can't I say that 'int' is a class and 'myclass'
  is a type?
 
  I might be wrong here, but I think the point is that there is no
  distinction. A class (lets call it SomeClass for this example) is an
  object of type 'type', and an instance of a class is an object of type
  'SomeClass'.

 But there seems to be a distinction:
  class int_class(object):

 ...   pass
 ...

  int_class

 class '__main__.int_class'

  int

 type 'int'

 why doesn't this print

  class int_class(object):

 ...   pass
 ...

  int_class

 type '__main__.int_class'

  int

 type 'int'

 or

  class int_class(object):

 ...   pass
 ...

  int_class

 class '__main__.int_class'

  int

 class 'int'

 If there is no distinction, how does the Python interpreter know when
 to print 'class' and when to print 'type'?


 There are some confusion about the terms here.

 Classes are instances of type 'type',

Could you please clarify what you mean with 'instance of type X'? I
guess you mean that 'y is an instance of type X' iif y is constructed
by instantiating X. Is that correct?

 What the type int means is that int is not a user type but a
 builtin type, instances of int are not types (or classes) but common
 objects, so its nature is the same as any classes.

 The way it prints doesn't matter, it's just the __repr__ of any instance, and 
 the default behavior for instances of type is to return 'class XX', but it 
 can be easily customized.

But 'int' is an instance of 'type' (the metaclass):

 int.__class__
type 'type'

so it should also return 'class int' if that's the default behavior
of the 'type' metaclass.

I think that to get 'type int' one would have to define a new
metaclass like this:

def type_meta(type):
def __repr__(self)
 return type %s % self.__name__

and then one should have int.__class__ == type_meta. But obviously
that's not the case. Why?


Moreover:

 class myint(int):
...pass
... 
 myint.__class__ == int.__class__
True
 int
type 'int'
 myint
class '__main__.myint'

despite int and myint having the same metaclass. So if the
representation is really defined in the 'type' metaclass, then
type.__repr__ has to make some kind of distinction between int and
myint, so they cannot be on absolute equal footing.



Best,

   -Nikolaus

-- 
 »It is not worth an intelligent man's time to be in the majority.
  By definition, there are already enough people to do that.«
 -J.H. Hardy

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
--
http://mail.python.org/mailman/listinfo/python-list

Re: win32com ChartObject pythonwin vs idle

2008-07-31 Thread sterling
On Jul 31, 4:28 am, Tim Golden [EMAIL PROTECTED] wrote:
 sterling wrote:
  I'm curious as to why the difference between IDLE and pythonWin when
  using win32com.
  opening an excel file, i've attempted to grab the chart information
  out of the file.

  commands like co = ChartObjects(1)  works in pythonWin but doesn't
  work in IDLE.

  however, on both co = chartobjects(1) works just fine.

 I can't speak for IDLE vs PythonWin but in general
 case-sensitivity of win32com stuff is related to
 early vs late Dispatch. If you've explicitly generated
 proxy modules for the Excel objects (via makepy,
 EnsureDispatch or whatever) then those are Python
 modules with case-sensitivity. If you're using dynamic
 dispatch then Python is simply passing your attribute
 name along to COM, which isn't case-sensitive, so either
 case will work.

 Not sure why IDLE vs PythonWin should make a difference
 here, but maybe the above explanation sheds some light...

 TJG

Thanks Tim.  I'm wondering if it's an OS issues with Vista (I'm
strangly ashamed to admit that both my laptop and main computer are
running it).
I decided to try the same code on my main computer (do most of my work
on my laptop) and the exact same thing has happened: I can run it in
pythonwin and not idle.
I found that I can't even run Open (I must have been running open()
previously):
i.e.
 import win32com.client
 ex = win32com.client.Dispatch(Excel.Application)
 wb = ex.Workbooks.Open(C:\Temp\SalesChart.xls)

Traceback (most recent call last):
  File pyshell#2, line 1, in module
wb = ex.Workbooks.Open(C:\Temp\SalesChart.xlsx)
  File C:\Python25\Lib\site-packages\win32com\client\dynamic.py,
line 467, in __getattr__
if self._olerepr_.mapFuncs.has_key(attr): return
self._make_method_(attr)
  File C:\Python25\Lib\site-packages\win32com\client\dynamic.py,
line 295, in _make_method_
methodCodeList =
self._olerepr_.MakeFuncMethod(self._olerepr_.mapFuncs[name],
methodName,0)
  File C:\Python25\Lib\site-packages\win32com\client\build.py, line
297, in MakeFuncMethod
return self.MakeDispatchFuncMethod(entry, name, bMakeClass)
  File C:\Python25\Lib\site-packages\win32com\client\build.py, line
318, in MakeDispatchFuncMethod
s = linePrefix + 'def ' + name + '(self' + BuildCallList(fdesc,
names, defNamedOptArg, defNamedNotOptArg, defUnnamedArg, defOutArg) +
'):'
  File C:\Python25\Lib\site-packages\win32com\client\build.py, line
604, in BuildCallList
argName = MakePublicAttributeName(argName)
  File C:\Python25\Lib\site-packages\win32com\client\build.py, line
542, in MakePublicAttributeName
return filter( lambda char: char in valid_identifier_chars,
className)
  File C:\Python25\Lib\site-packages\win32com\client\build.py, line
542, in lambda
return filter( lambda char: char in valid_identifier_chars,
className)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x83 in position
52: ordinal not in range(128)


but the exact same code works in PythonWin. Perhaps I will just find a
way to code everything I want in the older lowercase.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Swap memory in Python ? - three questions

2008-07-31 Thread John Nagle

Robert LaMarca wrote:

Hi,

I am using numpy and wish to create very large arrays.   My system is AMD 64
x 2 Ubuntu 8.04.  Ubuntu should be 64 bit. I have 3gb RAM and a 15 GB swap
drive.


Does a full 64-bit version of CPython, one where all pointers
and sizes are 64 bits, even exist?

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


Re: Function References

2008-07-31 Thread [EMAIL PROTECTED]
On Jul 31, 10:47 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 I take the freedom to do so as I see fit - this is usenet...

Fine, then keep beating a dead horse by replying to this thread with
things that do nobody any good. It seems like there are a lot better
way to waste time, though.

The Python/C API can get me back further without reliance on third-
party libraries than ctypes. It also isn't subject to the quirks that
ctypes is on platforms other than Windows (the target application runs
on Windows, Mac, and eventually Linux once the original distributor
has drivers for the device). I'm not even sure ctypes could load the
lib/driver the distributor packaged.

So really, I appreciate the option in ctypes, it's good stuff. But
it's not for this project.

Once again, the original question stands for anyone who has experience
with the Python/C API callbacks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Difference between type and class

2008-07-31 Thread Nikolaus Rath
Maric Michaud [EMAIL PROTECTED] writes:
 Le Thursday 31 July 2008 16:46:28 Nikolaus Rath, vous avez écrit :
 Maric Michaud [EMAIL PROTECTED] writes:
   Can someone explain to me the difference between a type and a class?
 
  If your confusion is of a more general nature I suggest reading the
  introduction of `Design Patterns' (ISBN-10: 0201633612), under
  `Specifying Object Interfaces'.
 
  In short: A type denotes a certain interface, i.e. a set of signatures,
  whereas a class tells us how an object is implemented (like a
  blueprint). A class can have many types if it implements all their
  interfaces, and different classes can have the same type if they share a
  common interface. The following example should clarify matters:
 
  Of course, this is what a type means in certain literature about OO
  (java-ish), but this absolutely not what type means in Python. Types
  are a family of object with a certain status, and they're type is
  type, conventionnaly named a metatype in standard OO.

 [...]

 Hmm. Now you have said a lot about Python objects and their type, but
 you still haven't said what a type actually is (in Python) and in what
 way it is different from a class. Or did I miss something?

 This paragraph ?

 
 - types, or classes, are all instance of type 'type' (or a subclass of it), 

Well, I couldn't quite make sense of '..are instance of type...'
without knowing what you actually meant with type* in this context,
but...

 Maybe it's still unclear that types and classes *are* synonyms
 in Python.

..in this case it becomes clear. Then my question reduces to the one
in the other post (why do 'int' and 'myint' have different __repr__
results).


Already thanks for your help,


   -Nikolaus

-- 
 »It is not worth an intelligent man's time to be in the majority.
  By definition, there are already enough people to do that.«
 -J.H. Hardy

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
--
http://mail.python.org/mailman/listinfo/python-list

Re: undo a dictionary

2008-07-31 Thread mmm
Gabriel,

I meant the latter, so this helps

 Or, do you mean you already have those names and values, perhaps mixed  
 with a lot more names, and want to extract only those starting with x  
 and following with a number?

 result = {}
 for name, value in vars(): # or locals().items(), or globals().items(), or  
 vars(some_module)
    if name[0]=='x' and name[1:].isdigit():
      result[name] = value

But I got an error with 'for name, value in vars():'
RuntimeError: dictionary changed size during iteration

I think globals() has the same problem, but globals.items() works. I
will need to read the docs to learn why '.items()' works but the
changing global dictionary problem makes sense.  I assume I need to
use a non dynamic created list.

Sometimes I get the error about 'too many variables to unpack' (can
not consistently repeat the error however)

In any event, thanks for the suggestions, everyone.

Using a blank class for unpacking the dictionary makes the most sense,
for safety sake.
So you know the general issue is I want to switch between using
dictionaries for storing data items and simple variable names for
writing equations/formulas, So (a) and (b) below are preferred to (c)
for readability

(a)  straight forward equation

  y = b0 + b1*Age + b2*Size

(b)  Class version

  y = b0 + b1*x.Age + b2*x.Size

(c)  Dictionary version

  y = b0 + b1*dd.get('Age') + b2*dd.get('Size')

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


Re: Difference between type and class

2008-07-31 Thread Maric Michaud
Le Thursday 31 July 2008 17:00:51 Nikolaus Rath, vous avez écrit :
  There are some confusion about the terms here.
 
  Classes are instances of type 'type',

 Could you please clarify what you mean with 'instance of type X'? I
 guess you mean that 'y is an instance of type X' iif y is constructed
 by instantiating X. Is that correct?


Correct, you can verify this with the isinstance builtin :

[1]: isinstance(int(), int)
...[1]: True

[2]: isinstance(int, object)
...[2]: True

[3]: isinstance(int, type)
...[3]: True

[4]: class A(object) : pass
   ...:

[5]: isinstance(A, type)
...[5]: True



  What the type int means is that int is not a user type but a
  builtin type, instances of int are not types (or classes) but common
  objects, so its nature is the same as any classes.
 
  The way it prints doesn't matter, it's just the __repr__ of any instance,
  and the default behavior for instances of type is to return 'class XX',
  but it can be easily customized.

 But 'int' is an instance of 'type' (the metaclass):
  int.__class__

 type 'type'

 so it should also return 'class int' if that's the default behavior
 of the 'type' metaclass.


The fact that a class is an instance of type, which it is always true, doesn't 
mean its metaclass is type, it could be any subclass of type :

[6]: class A(object) :
   ...: class __metaclass__(type) :
   ...: def __repr__(self) : return type A
   ...:
   ...:

[7]: isinstance(A, type)
...[7]: True

[8]: A.__class__
...[8]: class '__main__.__metaclass__'

[9]: issubclass(A.__class__, type)
...[9]: True


 I think that to get 'type int' one would have to define a new
 metaclass like this:

 def type_meta(type):
     def __repr__(self)
          return type %s % self.__name__

 and then one should have int.__class__ == type_meta. But obviously
 that's not the case. Why?

 Moreover:
  class myint(int):

 ...    pass
 ...

  myint.__class__ == int.__class__

 True


*is* comparaison fits better here.

  int

 type 'int'

  myint

 class '__main__.myint'

 despite int and myint having the same metaclass. So if the
 representation is really defined in the 'type' metaclass, then
 type.__repr__ has to make some kind of distinction between int and
 myint, so they cannot be on absolute equal footing.

You're right, type(int) is type, the way it renders differently is a detail of 
its implementation, you can do things with builtin types (written in C) you 
coudn't do in pure python, exactly as you couldn't write recursive types 
like 'object' and 'type'.


-- 
_

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

Re: Newbie Python questions

2008-07-31 Thread binaryjesus
One great open source GUI package that you left out is GTK ie. pygtk.
i cant compare it with wx as i have never used it but isay its much
better than QT.


Anyway for ur q if u want to compair qt n wx. QT should be faster coz
it has a better documentation.
and welcome to the python family!

kind regards
binaryjesus


On Jul 31, 12:10 pm, Tim Roberts [EMAIL PROTECTED] wrote:
 LessPaul [EMAIL PROTECTED] wrote:

 ...My
 question is in regard to GUI platforms. My primary target would be
 Windows, but I would also like be able to support Linux and Mac
 versions if possible. I'm also interested in using a system that also
 has support for pure C++ applications. As such, and after reading many
 web pages regarding Python GUIs, I believe I have the candidates
 narrowed down to pyQT and wxPython.

 The first question -- how steep is the curve to become proficient with
 the above GUI packages?

 There is so much personal preference here that it is extremely hard to give
 any guidance.  If you have done any Windows programming at all, so that you
 are familiar with the event-driven programming model, then I don't think
 you would see that much difference in learning curve.  The two packages are
 more alike than they are different -- the various APIs are just spelled
 differently.

 I happen to be a big wxPython fan.  I learn best by example, and wxPython
 has a 44,000-line demo suite with 167 source files that demonstrates
 virtually every class it includes.

 Since there appears to be no commercial licencing fee for wxWidgets/
 wxPython, the last question is what do I gain from going QT over wx?
 I've seen great applications written with both (on my computer I have
 the wxPython Digsby and the pyQT apps Mnemosyne and Anki. All seem
 to be solid.

 Yep.  Personal preference.
 --
 Tim Roberts, [EMAIL PROTECTED]
 Providenza  Boekelheide, Inc.



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


Re: current week / weeks in year - best practice

2008-07-31 Thread Aljosa Mohorovic
On Jul 31, 3:58 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 Instead of datetime.now() use date.today(), which removes a lot of
 boilerplate.

 int(date.today().strftime(%W))

 Apart from that, I think it's the way to go.

what if i know current context week = 20 (example), what would be the
best way to get datetime objects for first and last day of current
context week?
by current context week i don't mean current week for current year
but current week when program is iterating all weeks in year.

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


Re: Newbie Python questions

2008-07-31 Thread Mike Driscoll
On Jul 29, 12:28 pm, LessPaul [EMAIL PROTECTED] wrote:
 I recently discovered Python and see it as a great language to use for
 personal projects (and more). I made my living for over a decade as a
 coder in C, C++, ADA, Fortran, and Assembly before moving to systems
 engineering.

 I'm now retired, and would love to code again. I see Python as the
 perfect language to get a good program working in a short time. My
 question is in regard to GUI platforms. My primary target would be
 Windows, but I would also like be able to support Linux and Mac
 versions if possible. I'm also interested in using a system that also
 has support for pure C++ applications. As such, and after reading many
 web pages regarding Python GUIs, I believe I have the candidates
 narrowed down to pyQT and wxPython.

 The first question -- how steep is the curve to become proficient with
 the above GUI packages? If the answer is not very then there is no
 need for the following questions as I can try both on for size to see
 which I like best. However if it is a sizable investment in time, I'd
 like to maximize my efforts and choose the one I'll end up using in
 the end.

 The biggest hurdle I can see is the cost of the QT licence for
 commercial software, though apparently it can be acquired for a
 reasonable price via the BlackAdder package. Does purchasing the
 BlackAdder also include the needed software support for C++
 development? Does the BlackAdder purchase also allow for licence of
 standard C++ apps?

 Since there appears to be no commercial licencing fee for wxWidgets/
 wxPython, the last question is what do I gain from going QT over wx?
 I've seen great applications written with both (on my computer I have
 the wxPython Digsby and the pyQT apps Mnemosyne and Anki. All seem
 to be solid.

Tim forgot to mention that the wxPython user's group is very helpful
and fun. I don't know how the pyQT one is. You could try both toolkits
just working on some toy projects before you work on anything
commercial. Then they're both free! And you can find out which one
better suits you.

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


Re: current week / weeks in year - best practice

2008-07-31 Thread Aljosa Mohorovic
On Jul 31, 5:42 pm, Aljosa Mohorovic [EMAIL PROTECTED]
wrote:
 what if i know current context week = 20 (example), what would be the
 best way to get datetime objects for first and last day of current
 context week?
 by current context week i don't mean current week for current year
 but current week when program is iterating all weeks in year.

if w = current context week and now is current datetime object  this
is how i calculate days:
first_day = datetime.strptime(%s %s % (now.year, str((w-1)*7)), %Y
%j)
last_day = first_day + timedelta(days=6)

any comments on this?

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


Re: Function References

2008-07-31 Thread Matthew Woodcraft
 Ctypes is a since python2.5 built-in module that allows to declare
 interfaces to C-libraries in pure python. You declare datatypes and
 function prototypes, load a DLL/SO and then happily work with it. No C, no
 compiler, no refcounts, no nothing.

 And you can pass python-functions as callbacks.

[EMAIL PROTECTED] wrote:

 The first sentence (and some really crummy licensing restrictions
 imposed by the library distributor) alone here excludes this as a
 valid option for this particular case, I definitely need Python 2.4
 support.

Perhaps all is not lost: ctypes works from Python 2.3 up. That first
sentence is saying that since Python 2.5 it has been included in the
standard Python distribution, but you can still download it separately.

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


Re: Non Continuous Subsequences

2008-07-31 Thread Bruce Frederiksen
On Wed, 30 Jul 2008 09:32:25 -0700, bearophileHUGS wrote:

 This post is not about practical stuff, so if you have little time,
 you may ignore it.
 
 This is a task of the rosettacode.org site:
 http://www.rosettacode.org/wiki/Non_Continuous_Subsequences
 
 A subsequence contains some subset of the elements of this sequence,
 in the same order. A continuous subsequence is one in which no
 elements are missing between the first and last elements of the
 subsequence. The task is to enumerate all non-continuous subsequences
 for a given sequence.
 
 Translating the Scheme code to Python was easy (and I think this is
 quite more readable than the Scheme version):
 
 def ncsub(seq, s=0):
 if seq:
 x = seq[:1]
 xs = seq[1:]
 p2 = s % 2
 p1 = not p2
 return [x + ys for ys in ncsub(xs, s + p1)] + ncsub(xs, s +
 p2)
 else:
 return [[]] if s = 3 else []
 
 Output:
 
 ncsub(range(1, 4))
 [[1, 3]]
 ncsub(range(1, 5))
 [[1, 2, 4], [1, 3, 4], [1, 3], [1, 4], [2, 4]]
 ncsub(range(1, 6))
 [[1, 2, 3, 5], [1, 2, 4, 5], [1, 2, 4], [1, 2, 5], [1, 3, 4, 5], [1,
 3, 4], [1, 3, 5], [1, 3], [1, 4, 5], [1, 4], [1, 5], [2, 3, 5], [2, 4,
 5], [2, 4], [2, 5], [3, 5]]
 
 snip
 
 But in many cases you can create a lazy code in Python too, even if
 that may be harder. So I have tried to create a lazy version for
 Python, hoping to speed up the code avoiding the creation and joining
 of most/all sublists, but I have failed so far (once I have created a
 lazy Python version, I can probably create a short lazy version in D
 too, my D libs contain most of itertools module too).
 
 In my failed attempts I have used chain() to join the sublists,
 islice() to slice their items, and iter() to make the management more
 uniform when the input seq is a Python list instead of an xrange, etc.

Try this:

import itertools

def ncsub(seq, s = 0):
if seq:
x = seq[:1]
xs = seq[1:]
p2 = s % 2
p1 = 1 - p2
return itertools.chain(
   itertools.imap(lambda ys: x + ys, ncsub(xs, s + p1)),
   ncsub(xs, s + p2))
else:
return [[]] if s = 3 else []

 ncsub(range(1, 4))
itertools.chain object at 0xb7de528c
 list(ncsub(range(1, 4)))
[[1, 3]]
 list(ncsub(range(1, 5)))
[[1, 2, 4], [1, 3, 4], [1, 3], [1, 4], [2, 4]]
 list(ncsub(range(1, 6)))
[[1, 2, 3, 5], [1, 2, 4, 5], [1, 2, 4], [1, 2, 5], [1, 3, 4, 5], [1, 
3, 4], [1, 3, 5], [1, 3], [1, 4, 5], [1, 4], [1, 5], [2, 3, 5], [2, 4, 
5], [2, 4], [2, 5], [3, 5]]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Chris Mellon
On Tue, Jul 29, 2008 at 3:37 AM, Carl Banks [EMAIL PROTECTED] wrote:
 On Jul 28, 8:15 pm, Steven D'Aprano [EMAIL PROTECTED]
 cybersource.com.au wrote:
 On Mon, 28 Jul 2008 13:22:37 -0700, Carl Banks wrote:
  On Jul 28, 10:00 am, Steven D'Aprano [EMAIL PROTECTED]
  cybersource.com.au wrote:
  Cutting to the crux of the discussion...

  On Sun, 27 Jul 2008 23:45:26 -0700, Carl Banks wrote:
   I want something where if x will do but a simple explicit test
   won't.

  Explicit tests aren't simple unless you know what type x is. If x could
  be of any type, you can't write a simple test. Does x have a length? Is
  it a number? Maybe it's a fixed-length circular length, and the length
  is non-zero even when it's empty? Who knows? How many cases do you need
  to consider?

  Use case, please.  I'm asking for code, not arguments.  Please give me a
  piece of code where you can write if x that works but a simple
  explicit test won't.

 I gave you a piece of code, actual code from one of my own projects. If
 you wouldn't accept that evidence then, why would you accept it now?

 I would accept as evidence something that satisfies my criteria,
 which your example did not: it could have easily (and more robustly)
 been written with a simple explicit test.  I am looking for one that
 can't.

 You keep bringing up this notion of more complex with no benefit,
 which I'm simply not interested in talking about that at this time,
 and I won't respond to any of your points.  I am seeking the answer to
 one question: whether if x can usefully do something a simple
 explicit test can't.  Everyone already knows that if x requires
 fewer keystrokes and parses to fewer nodes.


I'm really not sure where you're going with this or what you're trying
to prove. if x is a duck-type test for a boolean value. Obviously if
you know the type and want a more *specific* test, then you can use an
explicit one. Any time you don't know or don't care about a more
specific type than something which probably is boolean true, or any
time where you know the boolean semantics of the type and want to drop
some typing, you can use if x. The more specific test is what you'd
use if you want more specific results. What's complicated about this
idea?
--
http://mail.python.org/mailman/listinfo/python-list


Re: problem when reading file

2008-07-31 Thread Bruce Frederiksen
On Thu, 31 Jul 2008 23:44:33 +1000, shrimpy wrote:

 hi every one, i am new to python,
 and coz i want to write a handy command for my linux machine, to find
 a word in all the files which are under the current folder.
 
 the code is half done, but when i run it, it complain, and i don`t know why???
 
 can anyone help me have a look at it?
 
 
 here is the message it complain
 ===
 file is : qt_plugins_3.3rc
 
 Traceback (most recent call last):
   File ./python_script/svn_grep.py, line 34, in module
 searPatten(file,'are','no')
   File ./python_script/svn_grep.py, line 8, in searPatten
 openFile = open(file, 'r')
 IOError: [Errno 2] No such file or directory: 'qt_plugins_3.3rc'
 
 
 here are the code i wrote
 ---code begin
 snip
 
 for root, dirs, files in os.walk(os.getcwd()):
   for file in files:
   print ===
   print file is :  + file + \n
   searPatten(file,'are','no')
 
 ---code end

Try changing that last line to:

 searPatten(os.path.join(root, file), 'are', 'no')


You'll have to import os.path too...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Function References

2008-07-31 Thread Carsten Haese

[EMAIL PROTECTED] wrote:

Greetings,

I'm trying to wrap a function in a C library as a compiled C Python
module. Everything is going great, but I've hit a snag. There's a
function in the form of this:

First the typedef:
typedef void(*FPtr_DeviceMessageHandler) (const DeviceMessage, const
char*);

Then the actual function prototype:
FPtr_DeviceMessageHandler
RegisterDeviceMessageHandler(FPtr_DeviceMessageHandler);
[...]
[I] can't figure out how to cast the function reference from Python into
something the C RegisterDevice... function can handle.


Mere casting won't do the trick. The function reference from Python is 
basically just an object that contains byte-code to be executed by the 
Python Virtual Machine. There is no way you can magically transform that 
into a C function by casting the Python object pointer to anything.


You'll need a write a C function that will call a given Python function, 
and then you need to supply the pointer to that C function as your 
DeviceMessageHandler callback function, and somehow communicate to your 
C function which Python function it should call.


Good luck.

--
Carsten Haese
http://informixdb.sourceforge.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Function References

2008-07-31 Thread Chris Mellon
On Thu, Jul 31, 2008 at 10:27 AM, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 On Jul 31, 10:47 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 I take the freedom to do so as I see fit - this is usenet...

 Fine, then keep beating a dead horse by replying to this thread with
 things that do nobody any good. It seems like there are a lot better
 way to waste time, though.

 The Python/C API can get me back further without reliance on third-
 party libraries than ctypes. It also isn't subject to the quirks that
 ctypes is on platforms other than Windows (the target application runs
 on Windows, Mac, and eventually Linux once the original distributor
 has drivers for the device). I'm not even sure ctypes could load the
 lib/driver the distributor packaged.

Ctypes works fine on many platforms. Since you didn't even know about
ctypes until you were told about it, don't you think it's a little
premature to be speculating about problems you haven't actually
experienced?

 So really, I appreciate the option in ctypes, it's good stuff. But
 it's not for this project.


It's actually perfectly suited, but you're (I'm assuming) and adult
and can make your own decisions...

 Once again, the original question stands for anyone who has experience
 with the Python/C API callbacks.
 --

If you know how to write a callback in C, you know how to do it with
Python/C. It's not real flexible if the callback API you're using
doesn't include user data, and it looks like it doesn't.

Ctypes can generate dynamic thunks and therefore will let you use any
Python object as a callback. It's a lot more flexible and it's a lot
easier to not write your own thunk generation in C.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Non Continuous Subsequences

2008-07-31 Thread bearophileHUGS
Bruce Frederiksen:

Your solution is a bit different from what I was thinking about (I was
thinking about a generator function, with yield), but it works.

This line:
 return itertools.chain(
itertools.imap(lambda ys: x + ys, ncsub(xs, s + p1)),
ncsub(xs, s + p2))

Can be written in a simpler way:
return chain((x + ys for ys in ncsub(xs, s + p1)), ncsub(xs, s + p2))

I'll think more about all this,
bye and thank you,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: Non Continuous Subsequences

2008-07-31 Thread Mensanator
On Jul 30, 11:32 am, [EMAIL PROTECTED] wrote:
 This post is not about practical stuff, so if you have little time,
 you may ignore it.

 This is a task of the rosettacode.org 
 site:http://www.rosettacode.org/wiki/Non_Continuous_Subsequences

 A subsequence contains some subset of the elements of this sequence,
 in the same order. A continuous subsequence is one in which no
 elements are missing between the first and last elements of the
 subsequence. The task is to enumerate all non-continuous subsequences
 for a given sequence.


That's equivalent to asking which n-bit binary numbers have
at least one 0 bracketed by 1s, isn't it?

import gmpy
import re

for i in xrange(32):
  s = gmpy.digits(i,2).zfill(5) # convert to base 2 (padded)
  m = re.search('10+1',s)   # at least one 0 between 1s
  if m:
z = [j+1 for j,i in enumerate(s) if i=='1']
print z

##  [3, 5]
##  [2, 5]
##  [2, 4]
##  [2, 4, 5]
##  [2, 3, 5]
##  [1, 5]
##  [1, 4]
##  [1, 4, 5]
##  [1, 3]
##  [1, 3, 5]
##  [1, 3, 4]
##  [1, 3, 4, 5]
##  [1, 2, 5]
##  [1, 2, 4]
##  [1, 2, 4, 5]
##  [1, 2, 3, 5]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Matthew Fitzgibbons

Steven D'Aprano wrote:

On Wed, 30 Jul 2008 09:23:05 -0600, Matthew Fitzgibbons wrote:


If you're expecting a list (and only a list)
then your point makes sense. 'if x' can get you into trouble if you
_don't_ want its polymorphism.


if x is hardly unique in that way. If you're expecting a list, and only 
a list, len(x) != 0 will get you in trouble if somebody passes a string 
or a dictionary. I don't see any reason why we should single out if x 
as dangerous in the face of invalid types. With the exception of the is 
and is not operators, nothing in Python is guaranteed to work with any 
imaginable object. Even print can fail, if the object's __str__ method 
raises an exception.


 

Although, if my function is expecting a list, my preference is to do:

if not isinstance(x, list):
 raise SomeMeaningfulException()
# do stuff with the list

I put my type checking at the top of the function, so readers can
reference it easily.


And thus you break duck-typing and upset anybody who wants to pass a 
sequence that doesn't inherit directly from list.


There are other (and arguably better, although more labour-intensive) 
techniques for defensive programming that don't break duck-typing. You 
can google for Look Before You Leap and Easier To Ask Forgiveness Than 
Permission for more information. Alex Martelli has a fine recipe in the 
Python Cookbook -- search for the recipe Checking if an object has the 
necessary attributes.


But in a nutshell, here's a toy example:

def spam(seq):
try:
seq.append
seq.extend
seq[0] = seq[0]
except Exception:
raise TypeError(argument isn't sufficiently sequence-like)
# No exceptions expected from here on
seq.append(seq[0])
seq.extend([1,2,3])
seq[0] = spam






Yes, I know it breaks duck typing, which is why I do it only very 
rarely, and never with e.g. sequence types. If I use ifinstance for type 
checking, it's because I need some _very_ specific class, almost always 
one that I wrote. My more usual use case for ifinstance is to figure out 
how to handle a particular object using introspection.


That said, your example is still helpful. It's a good approach, and I 
should use it more often. Although I'd also lean toward hasattr and 
iscallable and ordinary ifs instead of the try ... except where 
possible. Depending on what you put in the try ... except, you risk 
masking legit exceptions.


Ahhh, Programing. Where no rule of thumb seems to last five minutes.

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


Re: Python parsing iTunes XML/COM

2008-07-31 Thread Stefan Behnel
william tanksley wrote:
 I didn't
 pass a string. I passed a file. It didn't error out; instead, it
 produced bytestring-encoded output (not Unicode).

From my experience (and from the source code I have seen so far), ElementTree
does not return UTF-8 encoded strings at the API level. Can you produce any
evidence for your claims? Some code and an XML file that together produce the
result you are talking about? From what you have written so far, it seems far
more likely to me that your code is messed up than that you found a bug in
ElementTree.

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


Re: Difference between type and class

2008-07-31 Thread Nikolaus Rath
Maric Michaud [EMAIL PROTECTED] writes:
 What the type int means is that int is not a user type but a
 builtin type, instances of int are not types (or classes) but common
 objects, so its nature is the same as any classes.

 The way it prints doesn't matter, it's just the __repr__ of any instance,
 and the default behavior for instances of type is to return 'class XX',
 but it can be easily customized.

 But 'int' is an instance of 'type' (the metaclass):
  int.__class__

 type 'type'

 so it should also return 'class int' if that's the default behavior
 of the 'type' metaclass.


 The fact that a class is an instance of type, which it is always true, 
 doesn't 
 mean its metaclass is type, it could be any subclass of type :

Yes, that is true. But it's not what I said above (and below).
'obj.__class__' gives the class of 'obj', so if 'int.__class__ is
type' then 'type' is the class of 'int' and 'int' is *not* an instance
of some metaclass derived from 'type'.

 I think that to get 'type int' one would have to define a new
 metaclass like this:

 def type_meta(type):
     def __repr__(self)
          return type %s % self.__name__

 and then one should have int.__class__ is type_meta. But obviously
 that's not the case. Why?

 Moreover:
  class myint(int):

 ...    pass
 ...

  myint.__class__ is int.__class__
 True

  int
 type 'int'

  myint
 class '__main__.myint'

 despite int and myint having the same metaclass. So if the
 representation is really defined in the 'type' metaclass, then
 type.__repr__ has to make some kind of distinction between int and
 myint, so they cannot be on absolute equal footing.

 You're right, type(int) is type, the way it renders differently is a
 detail of its implementation, you can do things with builtin types
 (written in C) you coudn't do in pure python, exactly as you
 couldn't write recursive types like 'object' and 'type'.


If it is just a matter of different rendering, what's the reason for
doing it like that? Wouldn't it be more consistent and straightforward
to denote builtin types as classes as well?

And where exactly is this different rendering implemented? Could I
write my own type (in C, of course) and make it behave like e.g.
'int'? I.e. its rendering should be different and not inherited to
subclasses:


 my_type
strange_thing 'my_type'
 a = my_type(42)
 a.__class__
strange_thing 'my_type'

 class derived(my_type):
pass
class 'derived

or would I have to change the implemention of 'type' for this (since
it contains the __repr__ function that renders the type)?


This is of course purely theoretical and probably without any
practical relevance. I'm if I just can't stop drilling, but I think
this is really interesting.


Best,


   -Nikolaus

-- 
 »It is not worth an intelligent man's time to be in the majority.
  By definition, there are already enough people to do that.«
 -J.H. Hardy

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
--
http://mail.python.org/mailman/listinfo/python-list

Hobbyist - Python vs. other languages

2008-07-31 Thread fprintf
I have been playing with computers since I first learned to program
moving shapes on an Atari 800XL in BASIC. After many years of dabbling
in programming languages as a hobbyist (I am not a computer scientist
or other IT professional), I have never found a way to stick with a
language far enough to do anything useful.  I learn all about loops
and data structures and functions/methods etc. but never get to create
a program that will do anything of value that I can't more easily do
via freeware. Well, except the slot car timing system I wrote in C++
for Linux many moons ago.

Honestly Python seems like a breath of fresh air and possibly a way to
get back to my BASIC roots, you know, programming just for the fun of
it.

Since I don't have a specific problem to solve, besides
Pythonchallenge (which I found very cryptic), and Project Euler (which
I found beyond my mathematics skills), is there a place to go for
increasingly difficult problems to solve? I have followed a number of
the recommended online tutorials that contain a logical progression of
problems and yet they all end at the point where a person has enough
knowledge of the syntax, but not really enough to do anything.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Hobbyist - Python vs. other languages

2008-07-31 Thread Mike Driscoll
On Jul 31, 1:32 pm, fprintf [EMAIL PROTECTED] wrote:
 I have been playing with computers since I first learned to program
 moving shapes on an Atari 800XL in BASIC. After many years of dabbling
 in programming languages as a hobbyist (I am not a computer scientist
 or other IT professional), I have never found a way to stick with a
 language far enough to do anything useful.  I learn all about loops
 and data structures and functions/methods etc. but never get to create
 a program that will do anything of value that I can't more easily do
 via freeware. Well, except the slot car timing system I wrote in C++
 for Linux many moons ago.

 Honestly Python seems like a breath of fresh air and possibly a way to
 get back to my BASIC roots, you know, programming just for the fun of
 it.

 Since I don't have a specific problem to solve, besides
 Pythonchallenge (which I found very cryptic), and Project Euler (which
 I found beyond my mathematics skills), is there a place to go for
 increasingly difficult problems to solve? I have followed a number of
 the recommended online tutorials that contain a logical progression of
 problems and yet they all end at the point where a person has enough
 knowledge of the syntax, but not really enough to do anything.

I've noticed that there's a gap between learning the syntax and
actually being able to do something myself. It's pretty annoying.
However, all you need is to come up with some projects that you'd like
to do, such as inventorying some collection you have (CDs, DVDs,
Clocks, whatever). Then you have a place to start.

The next step is to break the project down into smaller parts until
you have parts to tackle. Let's say you want to inventory your DVDs
for example. First, you'd need to figure out how much data about each
title you want. Examples might include Title, Director, top 3 actors,
price, and purchase date. Once you know what you want to store, you
can learn about data persistence (i.e. databases!).

Or you could join a local Python Users Group or an open source
project. I learn a lot just helping people on this and other Python
lists.

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


Re: Hobbyist - Python vs. other languages

2008-07-31 Thread Serdar Tumgoren
From this noob's perspective, I'd say take a look at Magnus Lie
Hetland's Beginning
Pythonhttp://www.amazon.com/Beginning-Python-Novice-Professional/dp/159059519Xbook.
It covers the core syntax (which it sounds like you're familiar with
already) and then includes a bunch of projects, from text processing to cgi
programming to remote file editing and basic game programming. Granted, you
can find a lot of these examples as freeware, but I guess you stand to learn
plenty by extending the code he provides.

Good luck!

Serdar T.

On Thu, Jul 31, 2008 at 2:32 PM, fprintf [EMAIL PROTECTED] wrote:

 I have been playing with computers since I first learned to program
 moving shapes on an Atari 800XL in BASIC. After many years of dabbling
 in programming languages as a hobbyist (I am not a computer scientist
 or other IT professional), I have never found a way to stick with a
 language far enough to do anything useful.  I learn all about loops
 and data structures and functions/methods etc. but never get to create
 a program that will do anything of value that I can't more easily do
 via freeware. Well, except the slot car timing system I wrote in C++
 for Linux many moons ago.

 Honestly Python seems like a breath of fresh air and possibly a way to
 get back to my BASIC roots, you know, programming just for the fun of
 it.

 Since I don't have a specific problem to solve, besides
 Pythonchallenge (which I found very cryptic), and Project Euler (which
 I found beyond my mathematics skills), is there a place to go for
 increasingly difficult problems to solve? I have followed a number of
 the recommended online tutorials that contain a logical progression of
 problems and yet they all end at the point where a person has enough
 knowledge of the syntax, but not really enough to do anything.
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
Serdar Tumgoren
The Record
150 River Street
Hackensack, NJ 07601
201-403-0834
[EMAIL PROTECTED]
northjersey.com
--
http://mail.python.org/mailman/listinfo/python-list

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Matthew Fitzgibbons

Steven D'Aprano wrote:

On Wed, 30 Jul 2008 09:23:05 -0600, Matthew Fitzgibbons wrote:


If you're expecting a list (and only a list)
then your point makes sense. 'if x' can get you into trouble if you
_don't_ want its polymorphism.


if x is hardly unique in that way. If you're expecting a list, and only 
a list, len(x) != 0 will get you in trouble if somebody passes a string 
or a dictionary. I don't see any reason why we should single out if x 
as dangerous in the face of invalid types. With the exception of the is 
and is not operators, nothing in Python is guaranteed to work with any 
imaginable object. Even print can fail, if the object's __str__ method 
raises an exception.


Forgot respond to this point. I heartily agree. :) I singled out 'if x' 
only because that's the specific example under scrutiny. I think you and 
I are pretty much in agreement.


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


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Matthew Fitzgibbons

Matthew Fitzgibbons wrote:

Steven D'Aprano wrote:

On Wed, 30 Jul 2008 09:23:05 -0600, Matthew Fitzgibbons wrote:


If you're expecting a list (and only a list)
then your point makes sense. 'if x' can get you into trouble if you
_don't_ want its polymorphism.


if x is hardly unique in that way. If you're expecting a list, and 
only a list, len(x) != 0 will get you in trouble if somebody passes 
a string or a dictionary. I don't see any reason why we should single 
out if x as dangerous in the face of invalid types. With the 
exception of the is and is not operators, nothing in Python is 
guaranteed to work with any imaginable object. Even print can fail, if 
the object's __str__ method raises an exception.


 

Although, if my function is expecting a list, my preference is to do:

if not isinstance(x, list):
 raise SomeMeaningfulException()
# do stuff with the list

I put my type checking at the top of the function, so readers can
reference it easily.


And thus you break duck-typing and upset anybody who wants to pass a 
sequence that doesn't inherit directly from list.


There are other (and arguably better, although more labour-intensive) 
techniques for defensive programming that don't break duck-typing. You 
can google for Look Before You Leap and Easier To Ask Forgiveness Than 
Permission for more information. Alex Martelli has a fine recipe in 
the Python Cookbook -- search for the recipe Checking if an object 
has the necessary attributes.


But in a nutshell, here's a toy example:

def spam(seq):
try:
seq.append
seq.extend
seq[0] = seq[0]
except Exception:
raise TypeError(argument isn't sufficiently sequence-like)
# No exceptions expected from here on
seq.append(seq[0])
seq.extend([1,2,3])
seq[0] = spam






Yes, I know it breaks duck typing, which is why I do it only very 
rarely, and never with e.g. sequence types. If I use ifinstance for type 
checking, it's because I need some _very_ specific class, almost always 
one that I wrote. My more usual use case for ifinstance is to figure out 
how to handle a particular object using introspection.


That said, your example is still helpful. It's a good approach, and I 
should use it more often. Although I'd also lean toward hasattr and 
iscallable and ordinary ifs instead of the try ... except where 
possible. Depending on what you put in the try ... except, you risk 
masking legit exceptions.


Ahhh, Programing. Where no rule of thumb seems to last five minutes.

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



Where by ifinstance I mean isinstance and by iscallable I mean callable.

*hides*

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


simple problem with lists I am just forgetting

2008-07-31 Thread Alexnb

Lets say we have this list:

funlist = ['a', 'b', 'c']

and lets say I do this:

if funlist[4]:
print funlist[4]

I will get the exception list index out of range

How can I test if the list item is empty without getting that exception?
-- 
View this message in context: 
http://www.nabble.com/simple-problem-with-lists-I-am-just-forgetting-tp18762181p18762181.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: simple problem with lists I am just forgetting

2008-07-31 Thread bearophileHUGS
Alexnb:
 How can I test if the list item is empty without getting that exception?

In Python such list cell isn't empty, it's absent. So you can use
len(somelist) to see how much long the list is before accessing its
items. Often you can iterate on the list with a for, so you don't need
to care of the len().

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


Re: Hobbyist - Python vs. other languages

2008-07-31 Thread bearophileHUGS
fprintf:
 and yet they all end at the point where a person has enough
 knowledge of the syntax, but not really enough to do anything.

A programming language is a tool to solve problems, so first of all:
do you have problems to solve? You can create some visualizations,
some program with GUI, some networked code to download things and
process them, etc.

Another thing is that you probably have to learn beyond syntax, you
can learn about GUIs, network protocols, PyGame, mathematics, some
science, etc, they will give you both more things to learn (about the
language too) and problems/ideas to solve.

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


  1   2   3   >