Re: Newbie...

2011-02-25 Thread wisecracker
HI Steven...

> For *small* snippets, say, a single function, you can use the ActiveState 
> Cookbook:
> http://code.activestate.com/recipes/langs/python/
> A few random comments about your code:

Thanks duly noted...

>> # Original idea copyright, (C)2009, B.Walker, G0LCU.

> You can't copyright ideas.

True, but it is inside a Python file too. So therefore the idea is in a working 
state.

>> # >>> import afg[RETURN/ENTER]

> I thought you said you use only "STANDARD Python"? What's afg? It doesn't
> seem very standard to me:

> >>> import afg
> Traceback (most recent call last):
>   File "", line 1, in 
> ImportError: No module named afg

I made the mistake of making an assumption that intelligent guys like you
would know to save the first file as afg.py and the second as arp.py from the
import statements given... Oh well, can`t win `em all.

>> # Import any modules, ~sys~ is not rquired but added nevertheless.
>> import sys

> Don't do that. If you don't need a module, don't import it. *Especially* 
> don't import it only to say "Hey, you don't need this code, I'm just 
> wasting your time by making you read this!!!"

Duly noted...

>> # The program proper...
>> def main():
>>  # Make all variables global, a quirk of mine... :)

> It's not 1970 any more. People will avoid like the plague code that over-uses 
> globals.

Maybe not but I code for 10 year olds to understand and be able to modify 
easily, I build
HW for 10 year olds to make, modify and understand, I marry the two for 10 year 
olds to
modify and understand.

Mine is easy to understand even by programmer of limited knowledge.
Most of the Python code I`ve seen would be just visual 'noise' to a 10 year old.

>   sine=chr(15)+chr(45)+chr(63)+chr(45)+chr(15)+chr(3)+chr(0)+chr(3)

> This is much more easily and efficiently written as:

> sine = ''.join([chr(n) for n in (15, 45, 63, 45, 15, 3, 0, 3)])

> or even shorter, as a string constant:

> sine = '\x0f-?-\x0f\x03\x00\x03'

Now show your code to a 10 year old and see if he understands it...

Anyhow, thanks for the reply...

CYA...



--
73...

Bazza, G0LCU...

Team AMIGA...

http://homepages.tesco.net/wisecracker/

http://main.aminet.net/search?readme=wisecracker

http://mikeos.berlios.de/

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


Re: Newbie...

2011-02-25 Thread Corey Richardson
On 02/25/2011 03:18 AM, wisecrac...@tesco.net wrote:
> True, but it is inside a Python file too. So therefore the idea is in a 
> working state.

Then copyright the code.

>>> # >>> import afg[RETURN/ENTER]
> 
>> I thought you said you use only "STANDARD Python"? What's afg? It doesn't
>> seem very standard to me:
> 
> import afg
>> Traceback (most recent call last):
>>   File "", line 1, in 
>> ImportError: No module named afg
> 
> I made the mistake of making an assumption that intelligent guys like you
> would know to save the first file as afg.py and the second as arp.py from the
> import statements given... Oh well, can`t win `em all.

Should have specified that with header comment, for example:

###
## Copyright 2009, B.Walker, G0LCU.
## arp.py
##
## Something about this module
###

Or even better, a docstring.


>>> # The program proper...
>>> def main():
>>> # Make all variables global, a quirk of mine... :)
> 
>> It's not 1970 any more. People will avoid like the plague code that 
>> over-uses globals.
> 
> Maybe not but I code for 10 year olds to understand and be able to modify 
> easily, I build
> HW for 10 year olds to make, modify and understand, I marry the two for 10 
> year olds to
> modify and understand.

Teaching good practice to the young is better than teaching them easy
bad practice. It's taken me a too long to break out of my bad habits I
learned when I was 13 first learning Python.

> Mine is easy to understand even by programmer of limited knowledge.
> Most of the Python code I`ve seen would be just visual 'noise' to a 10 year 
> old.
> 
>>  sine=chr(15)+chr(45)+chr(63)+chr(45)+chr(15)+chr(3)+chr(0)+chr(3)
> 
>> This is much more easily and efficiently written as:
> 
>> sine = ''.join([chr(n) for n in (15, 45, 63, 45, 15, 3, 0, 3)])
> 
>> or even shorter, as a string constant:
> 
>> sine = '\x0f-?-\x0f\x03\x00\x03'
> 
> Now show your code to a 10 year old and see if he understands it...

When I was 10 all I knew was Logo (and very little of it)!

Also, if one understands how a unicode byte looks like in a string, it's
pretty easy to understand, and looks a hell of a lot clearer than a
bunch of chr()'s without any space between. That's just my two cents.

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


File-backed file system manipulation question

2011-02-25 Thread Chris Willmore
Hi All,

I have seen questions regarding mounting and dealing with root owned data, but 
nothing that appears to solve my particular issue.

I am creating an application that needs to mount VM images and do some 
manipulation (swap kernel, change fstab, etc). Most of the files and 
directories 
in the mounted image are owned by root, but of course I don't want to run the 
application as sudo. Is there anyway to get around using root at all (I can 
give 
any user access to a specified mnt point in fstab)? This is probably more of a 
Unix, systems question, but I'm interested to know if others have dealt with 
this in the Python domain.

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


Re: Newbie...

2011-02-25 Thread Corey Richardson
On 02/25/2011 03:39 AM, Corey Richardson wrote:
> Also, if one understands how a unicode byte looks like in a string, it's
> pretty easy to understand, and looks a hell of a lot clearer than a
> bunch of chr()'s without any space between. That's just my two cents.

Err..not a unicode byte, but it's some sort of escape sequence that
represents a byte. Not sure what it's called, to be honest.

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


Re: 2to3 chokes on bad character

2011-02-25 Thread Peter Otten
John Machin wrote:

> On Feb 25, 12:00 am, Peter Otten <__pete...@web.de> wrote:
>> John Machin wrote:
> 
>> > Your Python 2.x code should be TESTED before you poke 2to3 at it. In
>> > this case just trying to run or import the offending code file would
>> > have given an informative syntax error (you have declared the .py file
>> > to be encoded in UTF-8 but it's not).
>>
>> The problem is that Python 2.x accepts arbitrary bytes in string
>> constants.
> 
> Ummm ... isn't that a bug? According to section 2.1.4 of the Python
> 2.7.1 Language Reference Manual: """The encoding is used for all
> lexical analysis, in particular to find the end of a string, and to
> interpret the contents of Unicode literals. String literals are
> converted to Unicode for syntactical analysis, then converted back to
> their original encoding before interpretation starts ..."""
> 
> How do you reconcile "used for all lexical analysis" and "String
> literals are converted to Unicode for syntactical analysis" with the
> actual (astonishing to me) behaviour?

You are right, the current behaviour is probably an implementation accident 
stemming from the assumption that

s.decode("utf-8").encode("utf-8") == s

always holds. Other encodings (I tried cp1252) produce the expected 
SyntaxError.
-- 
http://mail.python.org/mailman/listinfo/python-list


Parsing numeric ranges

2011-02-25 Thread Seldon

Hi all,
I have to convert integer ranges expressed in a popular "compact" 
notation (e.g. 2, 5-7, 20-22, 41) to a the actual set of numbers (i.e. 
2,5,7,20,21,22,41).


Is there any library for doing such kind of things or I have to write it 
from scratch ?


Thanks in advance for any answers.

Seldon


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


Re: Parsing numeric ranges

2011-02-25 Thread Corey Richardson
On 02/25/2011 04:27 AM, Seldon wrote:
> Hi all,
> I have to convert integer ranges expressed in a popular "compact" 
> notation (e.g. 2, 5-7, 20-22, 41) to a the actual set of numbers (i.e. 
> 2,5,7,20,21,22,41).
> 
> Is there any library for doing such kind of things or I have to write it 
> from scratch ?
> 
> Thanks in advance for any answers.
> 
> Seldon
> 

I don't know of any library, but range() in Python 2 or list(range()) in
python 3 should provide the brunt force of what you're trying to do.

for example,

final_nums = [2]
compact_range = "5-7".split('-')
final_nums += range(int(compact_range[0]), int(compact_range[1]) + 1)

And then looping through your compact notation deciding when it's a
range notation and when it's a literal is all you have to do.

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


Re: Parsing numeric ranges

2011-02-25 Thread Alain Ketterlin
Seldon  writes:

> I have to convert integer ranges expressed in a popular "compact"
> notation (e.g. 2, 5-7, 20-22, 41) to a the actual set of numbers (i.e.
> 2,5,7,20,21,22,41).

What form does the input have? Are they strings, or some other
representation?

> Is there any library for doing such kind of things or I have to write
> it from scratch ?

What kind of result do you need? An explicit list? A generator?

Here is a naive solution where the input is a list of strings and the
result a generator:

def values(l):
for item in l:
bounds = item.split('-')
if len(bounds) == 1:
yield int(bounds[0])
elif len(bounds) == 2:
for v in range(int(bounds[0]),1+int(bounds[1])):
yield v
else:
pass # ignore, or throw, or...

# Use as in:
for x in values(["1","2-3","4-10"]):
print x

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


Re: Newbie...

2011-02-25 Thread Steven D'Aprano
On Fri, 25 Feb 2011 03:45:29 -0500, Corey Richardson wrote:

> On 02/25/2011 03:39 AM, Corey Richardson wrote:
>> Also, if one understands how a unicode byte looks like in a string,
>> it's pretty easy to understand, and looks a hell of a lot clearer than
>> a bunch of chr()'s without any space between. That's just my two cents.
> 
> Err..not a unicode byte, but it's some sort of escape sequence that
> represents a byte. Not sure what it's called, to be honest.

An escape sequence :)

Specifically, a hexadecimal escape. There are also octal escapes and 
character escapes like \n for newline.


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


Python encoding question

2011-02-25 Thread Marc Muehlfeld

Hi,

I'm doing my first steps with python and I have a problem with understanding 
an encoding problem I have. My script:


import os
os.environ["NLS_LANG"] = "German_Germany.UTF8"
import cx_Oracle
connection = cx_Oracle.Connection("username/password@SID")
cursor = connection.cursor()
cursor.execute("SELECT NAME1 FROM COR WHERE CORNB='ABCDEF'")
TEST = cursor.fetchone()
print TEST[0]
print TEST


When I run this script It prints me:
München
('M\xc3\xbcnchen',)

Why is the Umlaut of TEST[0] printed and not from TEST?


And why are both prints show the wrong encoding, when I switch "fetchone()" to 
"fetchall()":

('M\xc3\xbcnchen',)
[('M\xc3\xbcnchen',)]


I'm running Python 2.4.3 on CentOS 5.


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


Re: Python encoding question

2011-02-25 Thread Jean-Michel Pichavant

Marc Muehlfeld wrote:

Hi,

I'm doing my first steps with python and I have a problem with 
understanding an encoding problem I have. My script:


import os
os.environ["NLS_LANG"] = "German_Germany.UTF8"
import cx_Oracle
connection = cx_Oracle.Connection("username/password@SID")
cursor = connection.cursor()
cursor.execute("SELECT NAME1 FROM COR WHERE CORNB='ABCDEF'")
TEST = cursor.fetchone()
print TEST[0]
print TEST


When I run this script It prints me:
München
('M\xc3\xbcnchen',)

Why is the Umlaut of TEST[0] printed and not from TEST?


And why are both prints show the wrong encoding, when I switch 
"fetchone()" to "fetchall()":

('M\xc3\xbcnchen',)
[('M\xc3\xbcnchen',)]


I'm running Python 2.4.3 on CentOS 5.


Regards,
Marc

Nothing related to encoding here. TEST[0] is a string, TEST is a tupple.

s1 = 'aline \n anotherline'

> print str(s1)
aline
anotherline

> print repr(s1)
'aline \n anotherline'

atuple = (s1,)
> print str(atuple)
('aline \n anotherline',)

> print repr(atuple)
('aline \n anotherline',)

Read http://docs.python.org/reference/datamodel.html regarding __repr__ 
and __str__.


Basically, __str__ and __repr__ are the same method for tuples, while it 
differs from each other for strings.
If you want a nice representation of tuple elements you have to do it 
yourself:


print ', '.join([str(elem) for elem in atuple])

In a more general manner only strings will print nicely with carriage 
returns & UTF8 characters. Everyhing else, like tuple, lists, objects 
will using the __repr__ method which displays formal data.


JM
 
PS :


> class Foo:
   def __str__(self):
 return 'I am a nice representation of a Foo instance'



> print Foo()
I am a nice representation of a Foo instance

> print str(Foo())
I am a nice representation of a Foo instance

> print repr(Foo())
<__main__.Foo instance at 0xb73a07ac>



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


Today's Hottest actresses

2011-02-25 Thread Ashraf Ali
Hello friends, what's going on? Would you like to watch hollywood,
bollywood. tollywood, hot actresses pictures,biography, filmography.
Just visit
www.hotpics00.blogspot.com
www.hollywood-99.blogspot.com
www.hollywoodactors-99.blogspot.com
www.bollywoodactors00.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: Python fails on math

2011-02-25 Thread Heather Brown

On 01/-10/-28163 02:59 PM, Grant Edwards wrote:

On 2011-02-25, Steven D'Aprano  wrote:


C double *variables* are, but as John suggests, C compilers are allowed
(to my knowledge) to keep intermediate results of an expression in the
larger-precision FPU registers. The final result does get shoved back
into a 64-bit double when it is at last assigned back to a variable or
passed to a function that takes a double.


So...

(1) you can't rely on it, because it's only "allowed" and not mandatory;

(2) you may or may not have any control over whether or not it happens;

(3) it only works for calculations that are simple enough to fit in a
 single expression; and


  



In 1975, I was writing the arithmetic and expression handling for an 
interpreter.  My instruction primitives could add two bytes;  anything 
more complex was done in my code.  So I defined a floating point format 
(decimal, of course) and had extended versions of it available for 
intermediate calculations.  I used those extended versions, in logs for 
example, whenever the user of our language could not see the 
intermediate results.


When faced with the choice of whether to do the same inside explicit 
expressions, like  (a*b) - (c*d), I deliberately chose *not* to do such 
optimizations, in spite of the fact that it would improve both 
performance and (sometimes) accuracy.


I wrote down my reasons at the time, and they had to do with 'least 
surprise."  If a computation for an expression gave a different result 
than the same one decomposed into separate variables, the developer 
would have a hard time knowing when results might change, and when they 
might not.  Incidentally, the decimal format also assured "least 
surprise," since the times when quantization error entered in were 
exactly the same times as if one were doing the calculation by hand.


I got feedback from a customer who was getting errors in a complex 
calculation (involving trig), and wanted help in understanding why. 
While his case might have been helped by intermediate values having 
higher accuracy, the real solution was to reformulate the calculation to 
avoid subtracting two large numbers that differed by very little.  By 
applying a little geometry before writing the algorithm, I was able to 
change his accuracy from maybe a millionth of an inch to something 
totally unmeasurable.


I still think the choice was appropriate for a business language, if not 
for scientific use.


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


Re: Python encoding question

2011-02-25 Thread Dave Angel

On 01/-10/-28163 02:59 PM, Marc Muehlfeld wrote:

Hi,

  
TEST = cursor.fetchone()
print TEST[0]
print TEST


When I run this script It prints me:
München
('M\xc3\xbcnchen',)

Why is the Umlaut of TEST[0] printed and not from TEST?



When you print a string, it simply prints it, control characters, 
international characters, and all.


When you print a more complex object, it's up to that object to decide 
how to print.  In the case of a tuple above, the tuple logic displays 
the parentheses and the comma, but calls the repr() of any objects it 
contains.  Tuple doesn't make a special case for strings, or for 
numbers, it just always calls repr()   (actually it's __repr__(), I think)


A list does the same thing, though it'll use square brackets at the ends.

So the question boils down to what repr() does.  It attempts to create a 
representation that could be used to create the specific object.  So if 
there's a newline, it uses \n.  And if there are non-ASCII codes, it 
uses hex escape sequences.  And of course it adds the quote marks.


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


Re: Parsing numeric ranges

2011-02-25 Thread Seldon

On 02/25/2011 10:44 AM, Alain Ketterlin wrote:

Seldon  writes:


I have to convert integer ranges expressed in a popular "compact"
notation (e.g. 2, 5-7, 20-22, 41) to a the actual set of numbers (i.e.
2,5,7,20,21,22,41).


What form does the input have? Are they strings, or some other
representation?


Strings



What kind of result do you need? An explicit list? A generator?


A list.




Here is a naive solution where the input is a list of strings and the
result a generator:

def values(l):
 for item in l:
 bounds = item.split('-')
 if len(bounds) == 1:
 yield int(bounds[0])
 elif len(bounds) == 2:
 for v in range(int(bounds[0]),1+int(bounds[1])):
 yield v
 else:
 pass # ignore, or throw, or...

# Use as in:
for x in values(["1","2-3","4-10"]):
 print x



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


Re: lxml

2011-02-25 Thread Colin J. Williams

On 24-Feb-11 19:39 PM, alex23 wrote:

On Feb 24, 6:20 pm, Stefan Behnel  wrote:

MRAB, 24.02.2011 01:25:

The latest stable release is here:



http://pypi.python.org/pypi/lxml/2.2.8


Not quite the latest "stable release" (that would be 2.3), but at least one
that's pre-built for Windows.


Christoph Gohlke has an 'unofficial' Window's binaries site that
includes lxml 2.3 for Python 2.6, 2.7, 3.1 and 3.1:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

Very handy site.


Thanks,

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


Connect to FTP

2011-02-25 Thread sofia stouki
Hi all, 
 
I am trying to put together a script (Python 2.5, windows xp) that connects to 
an ftp server and retrieves/uploads files.
 
I am sure what I have put together is completely insufficient and I get the 
errors:
 
Traceback (most recent call last):
  File "C:\Documents and Settings\\Desktop\FTPDownload.py", line 19, in 
    ftp.login('username', 'password')
  File "C:\Python25\lib\ftplib.py", line 373, in login
    if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd)
  File "C:\Python25\lib\ftplib.py", line 241, in sendcmd
    return self.getresp()
  File "C:\Python25\lib\ftplib.py", line 216, in getresp
    raise error_perm, resp
error_perm: 530 User username cannot log in.
 
The script I have so far is :
 
from ftplib import FTP
def handleDownload(block):
    file.write(block)
    print ".",
    
ftp = FTP('servername')
# Log in to the server
print 'Logging in.'
# Specify username and password 
ftp.login('username', 'password') 
print ftp.login()
directory = '/test/ftp/'
# Change to that directory.  
print 'Changing to ' + directory
ftp.cwd(directory)
# Print the contents of the directory
ftp.retrlines('LIST')
 
 
but i cannot even connect to the FTP not to mention upload/download 
anything...So any ideas or suggestions would be greatly appreciated.
 
Thanks!
 


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


Re: Suggestion Reqd for Designing a Website in Python

2011-02-25 Thread joy99
On Feb 25, 12:36 pm, Tim Roberts  wrote:
> joy99  wrote:
>
> >Dear Group,
> >I have developed one big Machine Learning software a Machine
> >Translation system in Python.
> >Now, I am thinking to make a User Interface of it and upload it in a
> >web site.
>
> Do you mean you want people to download this from a web site as an
> executable, and then run it locally on their computers?  Or do you mean you
> want people to use this as a web site, using their web browsers?  The
> answers are very different.
>
> >My questions are:
> >(i) For Designing an interface I am choosing Tkinter. Is it fine?
> >(ii) How to connect this interface with my Tkinter based interface -
> >should I have to recode the whole system?
> >(iii) After designing I want to upload now how to do the server side
> >scripting?
>
> Question (i) implies that you want the first option (download an executable
> and run it).  Question (iii) implies the second (that you want your app to
> run on a web server so people use it through your browser).  Please
> clarify.
> --
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.

Thank you for your kind reply.
I want to design an interface like Google Translate. So that users can
paste text (of any length)-or may browse files which can be uploaded,
and one user interface for filling up form, so that attached files
after translation may be sent back to the given e-mail id as an
attached file(.pdf/.txt).
Best Regards,
Subhabrata.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suggestion Reqd for Designing a Website in Python

2011-02-25 Thread Daniel Fetchinson
>> >I have developed one big Machine Learning software a Machine
>> >Translation system in Python.
>> >Now, I am thinking to make a User Interface of it and upload it in a
>> >web site.
>>
>> Do you mean you want people to download this from a web site as an
>> executable, and then run it locally on their computers?  Or do you mean
>> you
>> want people to use this as a web site, using their web browsers?  The
>> answers are very different.
>>
>> >My questions are:
>> >(i) For Designing an interface I am choosing Tkinter. Is it fine?
>> >(ii) How to connect this interface with my Tkinter based interface -
>> >should I have to recode the whole system?
>> >(iii) After designing I want to upload now how to do the server side
>> >scripting?
>>
>> Question (i) implies that you want the first option (download an
>> executable
>> and run it).  Question (iii) implies the second (that you want your app to
>> run on a web server so people use it through your browser).  Please
>> clarify.
>> --
>> Tim Roberts, t...@probo.com
>> Providenza & Boekelheide, Inc.
>
> Thank you for your kind reply.
> I want to design an interface like Google Translate. So that users can
> paste text (of any length)-or may browse files which can be uploaded,
> and one user interface for filling up form, so that attached files
> after translation may be sent back to the given e-mail id as an
> attached file(.pdf/.txt).
> Best Regards,
> Subhabrata.

In this case you are looking for a web application framework. There
are many written in python, a good place to start would be:

http://wiki.python.org/moin/WebFrameworks

My personal opinion is that the 3 top frameworks to consider are: (1)
django (2) turbogears (3) web2py. You need to decide for yourself
which one use choose, you may even choose something other than these
3, there are tons more.

Cheers,
Daniel



-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Yappi error "context not found"

2011-02-25 Thread Brian
Thanks - I've opened a ticket at
http://code.google.com/p/yappi/issues/detail?id=21

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


getpass and IDEs

2011-02-25 Thread Andrew
I find that calling getpass produces a warning noting that it can't
suppress output, if I'm using idle, wingide, or a few others. If I'm
running from the console it works fine, but then I can't make use of
ide-integrated debugging. 

I know I could just set up a test account for development purposes if
I'm concerned about shoulder surfers, and that's probably a good idea
anyway. But I'm curious what's different about IDE environments that
makes it impossible to suppress output on them, and if there's anything
that might be done about this. 

--

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


Make a buildout based application standalone

2011-02-25 Thread Oleksandr Kozachuk
Hi!

I try to create a standalone installable version of BlueBream, but also with
other appications: What is required to do, to install some Buildout based
application without internet connection?

The first problem is to create a full dependency list and download all
packages. The next is to install it on the target system in right order.

I think it should be done recipes or similar for it, but i can not find it ...

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


Re: Suggestion Reqd for Designing a Website in Python

2011-02-25 Thread joy99
On Feb 25, 8:03 pm, Daniel Fetchinson 
wrote:
> >> >I have developed one big Machine Learning software a Machine
> >> >Translation system in Python.
> >> >Now, I am thinking to make a User Interface of it and upload it in a
> >> >web site.
>
> >> Do you mean you want people to download this from a web site as an
> >> executable, and then run it locally on their computers?  Or do you mean
> >> you
> >> want people to use this as a web site, using their web browsers?  The
> >> answers are very different.
>
> >> >My questions are:
> >> >(i) For Designing an interface I am choosing Tkinter. Is it fine?
> >> >(ii) How to connect this interface with my Tkinter based interface -
> >> >should I have to recode the whole system?
> >> >(iii) After designing I want to upload now how to do the server side
> >> >scripting?
>
> >> Question (i) implies that you want the first option (download an
> >> executable
> >> and run it).  Question (iii) implies the second (that you want your app to
> >> run on a web server so people use it through your browser).  Please
> >> clarify.
> >> --
> >> Tim Roberts, t...@probo.com
> >> Providenza & Boekelheide, Inc.
>
> > Thank you for your kind reply.
> > I want to design an interface like Google Translate. So that users can
> > paste text (of any length)-or may browse files which can be uploaded,
> > and one user interface for filling up form, so that attached files
> > after translation may be sent back to the given e-mail id as an
> > attached file(.pdf/.txt).
> > Best Regards,
> > Subhabrata.
>
> In this case you are looking for a web application framework. There
> are many written in python, a good place to start would be:
>
> http://wiki.python.org/moin/WebFrameworks
>
> My personal opinion is that the 3 top frameworks to consider are: (1)
> django (2) turbogears (3) web2py. You need to decide for yourself
> which one use choose, you may even choose something other than these
> 3, there are tons more.
>
> Cheers,
> Daniel
>
> --
> Psss, psss, put it down! -http://www.cafepress.com/putitdown

Thank you sir, for your kind help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing numeric ranges

2011-02-25 Thread Simon Brunning
On 25 February 2011 09:27, Seldon  wrote:
> Hi all,
> I have to convert integer ranges expressed in a popular "compact" notation
> (e.g. 2, 5-7, 20-22, 41) to a the actual set of numbers (i.e.
> 2,5,7,20,21,22,41).
>
> Is there any library for doing such kind of things or I have to write it
> from scratch ?

I dredged this out:



def _revision_list_with_ranges_to_list_without_ranges(revision_list):
'''Convert a revision list with ranges (e.g. '1,3,5-7') to a
simple list without ranges (1,3,5,6,7)'''
for revision in revision_list:
if '-' in revision:
from_revision, _, to_revision = revision.partition('-')
for revision_in_range in range(int(from_revision),
int(to_revision)+1):
yield revision_in_range
else:
yield int(revision)

-- 
Cheers,
Simon B.
-- 
http://mail.python.org/mailman/listinfo/python-list


Removing hidden directory in os.walk()

2011-02-25 Thread Gaëtan Podevijn
Hello,

I would like that os.walk() does not walk through hidden directories. I know
that with topdow = true, I can modify the subdirectory list in place, but
how should I remove every hidden directory from this place in list ?

Thank you,
Gaëtan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing hidden directory in os.walk()

2011-02-25 Thread Chris Rebert
On Fri, Feb 25, 2011 at 9:40 AM, Gaëtan Podevijn  wrote:
> Hello,
> I would like that os.walk() does not walk through hidden directories. I know
> that with topdow = true, I can modify the subdirectory list in place, but
> how should I remove every hidden directory from this place in list ?

Assuming you're on *nix:

for dirpath, dirnames, filenames in os.walk(top):
dirnames[:] = [d for d in dirnames if not d.startswith('.')]
do_whatever()

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Connect to FTP

2011-02-25 Thread Chris Rebert
On Fri, Feb 25, 2011 at 6:37 AM, sofia stouki  wrote:
>
> Hi all,
>
> I am trying to put together a script (Python 2.5, windows xp) that connects 
> to an ftp server and retrieves/uploads files.
>
> I am sure what I have put together is completely insufficient and I get the 
> errors:
>
> Traceback (most recent call last):
>   File "C:\Documents and Settings\\Desktop\FTPDownload.py", line 19, in 
> 
>     ftp.login('username', 'password')
>   File "C:\Python25\lib\ftplib.py", line 373, in login
>     if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd)
>   File "C:\Python25\lib\ftplib.py", line 241, in sendcmd
>     return self.getresp()
>   File "C:\Python25\lib\ftplib.py", line 216, in getresp
>     raise error_perm, resp
> error_perm: 530 User username cannot log in.
>
> The script I have so far is :
>
> from ftplib import FTP
> def handleDownload(block):
>     file.write(block)
>     print ".",
>
> ftp = FTP('servername')
> # Log in to the server
> print 'Logging in.'
> # Specify username and password
> ftp.login('username', 'password')
> print ftp.login()
> directory = '/test/ftp/'
> # Change to that directory.
> print 'Changing to ' + directory
> ftp.cwd(directory)
> # Print the contents of the directory
> ftp.retrlines('LIST')
>
>
> but i cannot even connect to the FTP not to mention upload/download 
> anything...So any ideas or suggestions would be greatly appreciated.

Looks like your username-password pair is invalid. Have you checked
whether your credentials work using another FTP client? Have you
checked whether you need to securely login using TLS?

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


Can you recommend an Experienced Python/SQL contract developer for this 6 - 12 month contract in NYC?

2011-02-25 Thread Ben B. Diamond
Experienced Python/SQL contract developer

* 3+ years experience writing clean, concise Python
* 3+ years experience tracing, debugging, and maintaining existing code
* Experience working closely with a team in a fluid environment with
evolving requirements
* Strong CS fundamentals (algorithms & data structures)
* Nice to have: Experience writing and tuning SQL queries
* Nice to have: Unix scripting / ops / "handyman" experience
* strong Python skills
* experience with Python web servers (Tornado experience a plus)
* experience with HTML templates
* strong SQL skills (MS SQL Server a plus)
* experience optimizing database views using clustered indexes or other
database structures
* Linux server administration skills, experience with puppet and/or
fabric is a huge plus
* any of nginx, memcached, mongodb experience a plus
* Ability to self-manage and stay productive by oneself
* Ability to work with stakeholders to formulate system requirements
* Works well with both developers and non-developers.
* Flexible work schedule (ie-willing to work off-hours, if necessary)
* experience with Javascript and complex CSS styling
* CDN experience (Rackspace cloudfiles a huge plus)
* experience with writing scheduling and/or learning algorithms
* MS Excel spreadsheet skills



Thanks,

Ben Diamond
The Forum Group
Information Technologies Division
260 Madison Ave
Suite 200
NY, NY 10016
T. 212 687 4050 x355

C. 201 313 6009
www.forumgrp.com 









Providing specialized permanent and contract staffing services since
1974

Accounting & Taxation   |   Human Resources  |  Office Support
Administration  | Legal |  Advertising/Communications/Creative Services
Marketing/Market Research |  Information Technology  | Finance & Banking
| Healthcare







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


Re: getpass and IDEs

2011-02-25 Thread Wolfgang Rohdewald
On Freitag 25 Februar 2011, Andrew wrote:
> I find that calling getpass produces a warning noting that it
> can't suppress output, if I'm using idle, wingide, or a few
> others. If I'm running from the console it works fine, but
> then I can't make use of ide-integrated debugging.
> 
> I know I could just set up a test account for development
> purposes if I'm concerned about shoulder surfers, and that's
> probably a good idea anyway. But I'm curious what's different
> about IDE environments that makes it impossible to suppress
> output on them, and if there's anything that might be done
> about this.

I'd say your IDE redirects stdout/stderr so it can show
output within the IDE

http://docs.python.org/library/getpass.html
reading python docs lets me believe you are using
python pre 2.6

if so, you could try to open a stream to /dev/tty and pass
that to getpass.getpass()

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


Re: Can you recommend an Experienced Python/SQL contract developer for this 6 - 12 month contract in NYC?

2011-02-25 Thread Daniel Mahoney
> Thanks,
> 
> Ben Diamond
> The Forum Group
> Information Technologies Division
> 260 Madison Ave
> Suite 200
> NY, NY 10016
> T. 212 687 4050 x355
> 
> C. 201 313 6009
> www.forumgrp.com 


PLEASE, don't include all that Microsoft HTML crap at the end of your 
post! Good old plain text works just fine for both Usenet newsgroups and 
e-mail lists.

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


Re: Parsing numeric ranges

2011-02-25 Thread Suneel Kingrani


very well done..
But I thought it may require a little bit of change in the proposed code.. :)

def _revision_list_with_ranges_to_list_without_ranges(revision_list):
for revision in revision_list.split(','):
if '-' in str(revision):
from_revision, _, to_revision = str(revision).partition('-')
for revision_in_range in range(int(from_revision),
int(to_revision)+1):
yield revision_in_range
else:
yield int(revision)



cheers:
suneel kingrani





From: Simon Brunning 
To: Seldon 
Cc: python-list@python.org
Sent: Fri, 25 February, 2011 10:36:10 PM
Subject: Re: Parsing numeric ranges

On 25 February 2011 09:27, Seldon  wrote:
> Hi all,
> I have to convert integer ranges expressed in a popular "compact" notation
> (e.g. 2, 5-7, 20-22, 41) to a the actual set of numbers (i.e.
> 2,5,7,20,21,22,41).
>
> Is there any library for doing such kind of things or I have to write it
> from scratch ?

I dredged this out:



def _revision_list_with_ranges_to_list_without_ranges(revision_list):
'''Convert a revision list with ranges (e.g. '1,3,5-7') to a
simple list without ranges (1,3,5,6,7)'''
for revision in revision_list:
if '-' in revision:
from_revision, _, to_revision = revision.partition('-')
 for revision_in_range in range(int(from_revision),
int(to_revision)+1):
yield revision_in_range
else:
yield int(revision)

-- 
Cheers,
Simon B.
-- 
http://mail.python.org/mailman/listinfo/python-list

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


Re: getpass and IDEs

2011-02-25 Thread Andrew
On Fri, 25 Feb 2011 20:27:42 +0100, Wolfgang Rohdewald wrote:

> On Freitag 25 Februar 2011, Andrew wrote:

>> But I'm curious what's different
>> about IDE environments that makes it impossible to suppress
>> output on them, and if there's anything that might be done
>> about this.
> 
> I'd say your IDE redirects stdout/stderr so it can show
> output within the IDE
> 
> http://docs.python.org/library/getpass.html
> reading python docs lets me believe you are using
> python pre 2.6

3.2. Though maybe you're right anyway. Does IDLE redirect in that
fashion? Why would that interfere with getpass? 

I'm less concerned about how to get around it as with figuring out why
it does it. More curiosity than practicality. 

--

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


Re: wxPython SQLite and Reportlab demo

2011-02-25 Thread Beppe
On 25 Feb, 08:33, Tim Roberts  wrote:
> Beppe  wrote:
>
> >I would recommend this my little work on sourceforge.
>
> >http://sourceforge.net/projects/pyggybank/
>
> >you can download an exe (pyggy_w32.7z)  make with py2exe
> >and the source  (pyggy_source.7z)
> >the project is named Pyggy Bank.
>
> Nowhere, in either this announcement or your sourceforge.net page, do you
> say a single word about what this application actually is.
>
> Just a few sentences describing what the application does would go a long
> way toward stirring up interest in this app.
> --
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.

Right Tim,
I will improve this as soon as possible.

regards
Beppe

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


ANN: Intro+Intermediate Python course, SF, May 24-26

2011-02-25 Thread wesley chun
Need to get up-to-speed with Python as quickly and as in-depth as
possible? Already coding Python but still have areas of uncertainty
you need to fill? Then come join me, Wesley Chun, author of
Prentice-Hall's bestseller "Core Python" for a comprehensive
intro/intermediate course coming up this May in Northern California,
then enjoy the Memorial Day weekend afterwards in San Francisco, the
beautiful city by the bay.

Please pass on this note to whomever you think may be interested. I
look forward to meeting you and your colleagues! feel free to pass
around the PDF flyer linked down below.

(Comprehensive) Introduction to Python
Tue-Thu, 2010 May 24-26, 9am-5pm

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(COMPREHENSIVE) INTRO+INTERMEDIATE PYTHON

Although this course may appear to those new to Python, it is also
perfect for those who have tinkered with it and want to "fill in the
gaps" and/or want to get more in-depth formal training.  It combines
the best of both an introduction to the language as well as a "Python
Internals" training course.

We will immerse you in the world of Python in only a few days, showing
you more than just its syntax (which you don't really need a book to
learn, right?). Knowing more about how Python works under the covers,
including the relationship between data objects and memory management,
will make you a much more effective Python programmer coming out of
the gate. 3 hands-on labs each day will help hammer the concepts home.

Come find out why Google, Yahoo!, Disney, ILM/LucasFilm, VMware,
NASA, Ubuntu, YouTube, and Red Hat all use Python. Users supporting or
jumping to Plone, Zope, TurboGears, Pylons, Django, Google App Engine,
Jython, IronPython, and Mailman will also benefit!

PREVIEW 1: you will find (and can download) a video clip of a
class session recorded live to get an idea of my lecture style and
the interactive classroom environment (as well as sign-up) at:

http://cyberwebconsulting.com

PREVIEW 2: Partnering with O'Reilly and Pearson, Safari Books
Online has asked me to deliver a 1-hour webcast a couple of years ago
called "What is Python?". This was an online seminar based on a
session that I've delivered at numerous conferences in the past. It
will give you an idea of lecture style as well as an overview of the
material
covered in the course.

info:http://www.safaribooksonline.com/events/WhatIsPython.html
download (reg req'd):
http://www.safaribooksonline.com/Corporate/DownloadAndResources/webcastInfo.php?page=WhatIsPython
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

WHERE: near the San Francisco Airport (SFO/San Bruno), CA, USA

WEB:   http://cyberwebconsulting.com

FLYER: http://cyberwebconsulting.com/flyerPP1.pdf

LOCALS: easy freeway (101/280/380) with lots of parking plus public
transit (BART and CalTrain) access via the San Bruno stations, easily
accessible from all parts of the Bay Area

VISITORS: free shuttle to/from the airport, free high-speed internet,
free breakfast and regular evening receptions; fully-equipped suites

See website for costs, venue info, and registration. There is a
significant discounts available for full-time students, secondary
teachers, and others.

Hope to see you there!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
    http://corepython.com

wesley.chun : wescpy-gmail.com : @wescpy
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter: The good, the bad, and the ugly!

2011-02-25 Thread Gregory Ewing

[Sorry to revive an old thread, but I was away when it occurred
and I'd like to make a comment...]

Kevin Walzer wrote:

This library isn't much different from other Python GUI toolkits--it's 
dependent on underlying, rather large, platform-specific 
implementations--but it provides an even higher level of abstraction. On 
the Mac, it is dependent on PyObjC;  on Windows, pywin32; and on X11, 
pygtk. In short, it's a wrapper over other wrappers.


PyGUI differs from the likes of wxPython and PyQT in that the
things it depends on are mainly just Python bindings for native
facilities already present on the platform.

This is an issue because of the number of API translations
involved. WxWidgets and Qt are themselves cross-platform libraries
that present quite a different API from the platform. The Python
bindings for them just expose that API to Python, resulting in
something that is not very Pythonic. To fix that, you would need
another layer on top, resulting in *two* API translations.

Each time such a translation occurs, something gets lost. PyGUI
is designed to minimise the loss by building a Pythonic API
directly on the platform API.

To me, this is the most important thing. Minimising the size of
third-party dependencies is also a goal, but it's secondary, and
can be addressed in various ways later, such as by using ctypes
or custom extension modules. Getting the API right, and proving
that it can be implemented with acceptable quality on all the
target platforms, are the first priorities.

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


py3k: datetime resolution / isoformat

2011-02-25 Thread spam


When I do:

datetime.datetime.now().isoformat(' ')

I get the time with the microseconds. The docs says:
"if microsecond is 0 -MM-DDTHH:MM:SS+HH:MM".

How do I set microsecond to 0?

 >>> datetime.datetime.microsecond = 0
Traceback (most recent call last):
  File "", line 1, in 
TypeError: can't set attributes of built-in/extension type 
'datetime.datetime'



>>> datetime.datetime.resolution = (0, 0, 0)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: can't set attributes of built-in/extension type 
'datetime.datetime'


Do I need to create my own class to extend datetime.datetime?

--
Yves.  http://www.SollerS.ca/
   http://blog.zioup.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: py3k: datetime resolution / isoformat

2011-02-25 Thread Ned Deily
In article , s...@uce.gov wrote:
> When I do:
> 
>  datetime.datetime.now().isoformat(' ')
> 
> I get the time with the microseconds. The docs says:
> "if microsecond is 0 -MM-DDTHH:MM:SS+HH:MM".
> 
> How do I set microsecond to 0?

>>> datetime.datetime.now().replace(microsecond=0).isoformat()
'2011-02-25T18:48:24'

-- 
 Ned Deily,
 n...@acm.org

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


Re: py3k: datetime resolution / isoformat

2011-02-25 Thread MRAB

On 26/02/2011 02:21, s...@uce.gov wrote:


When I do:

datetime.datetime.now().isoformat(' ')

I get the time with the microseconds. The docs says:
"if microsecond is 0 -MM-DDTHH:MM:SS+HH:MM".

How do I set microsecond to 0?

 >>> datetime.datetime.microsecond = 0
Traceback (most recent call last):
File "", line 1, in 
TypeError: can't set attributes of built-in/extension type
'datetime.datetime'


 >>> datetime.datetime.resolution = (0, 0, 0)
Traceback (most recent call last):
File "", line 1, in 
TypeError: can't set attributes of built-in/extension type
'datetime.datetime'

Do I need to create my own class to extend datetime.datetime?


You could just truncate the result:

datetime.datetime.now().isoformat(' ')[ : 19]
--
http://mail.python.org/mailman/listinfo/python-list


Re: py3k: datetime resolution / isoformat

2011-02-25 Thread Chris Rebert
On Fri, Feb 25, 2011 at 6:21 PM,   wrote:
>
> When I do:
>
>    datetime.datetime.now().isoformat(' ')
>
> I get the time with the microseconds. The docs says:
> "if microsecond is 0 -MM-DDTHH:MM:SS+HH:MM".
>
> How do I set microsecond to 0?
>
>     >>> datetime.datetime.microsecond = 0
>    Traceback (most recent call last):
>      File "", line 1, in 
>    TypeError: can't set attributes of built-in/extension type
> 'datetime.datetime'

Here you're trying to modify the *class* itself, not an *instance* of
the class like you want to.
However, datetime.datetime instances are immutable anyway. You have to
create a new instance with the desired values, as Ned Deily
demonstrated.

Cheers,
Chris
--
Your "From:" address is annoying.
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess pipe question

2011-02-25 Thread Rita
The results look right! I did a rather large test and the checksum passed.

I will hold off any speed ups as you suggested.

On Wed, Feb 23, 2011 at 8:37 PM, Rob Williscroft  wrote:

> Rita wrote in
> news:AANLkTi=88dcpm_kqrs2g620obsnxz0majubfwpeme...@mail.gmail.com in
> gmane.comp.python.general:
>
> [Top post relocated]
>
> > On Tue, Feb 22, 2011 at 7:57 PM, Rob Williscroft 
> > wrote:
> >
> >> Rita wrote in
> >> news:AANLkTi=w95gxosc1tkt2bntgjqys1cbmdnojhokq4...@mail.gmail.com in
> >> gmane.comp.python.general:
> >>
> >> >
> >> > When using wait() it works a bit better but not consistent
> >> > def run(cmd):
> >> >   p=subprocess.Popen(cmd,stdout=subprocess.PIPE)
> >> >   rc=p.wait()
> >> >   print rc
> >> >   return p.stdout
> >> >
> >>
> >> > When the output of cmd is a small ascii file it works perfectly
> >> > fine, but when the file is large (more than 2MB) the process just
> >> > waits for ever (I am guessing its blocking?).
> >>
> >> Your OS has supplied a pipe buffer of 2MB, its full and the prossess
> >> is waiting until you read something from the pipe (i.e.
> >> p.stdout.read()).
> >>
> >> >When I use the communicate call
> >> > it works perfectly but my process is consuming way too much memory.
> >> >
> >> > Is there a better way to get my return code consistently
> >> > efficiently and not take up so much memory?
> >>
> >> If you don't need the processes output then don't use the PIPE
> >> argument. If you do you will need to read from p.stdout until the
> >> process is complete, then get the return code:
> >>
> >> while True:
> >>buf = p.stdout.read( 1024 )
> >># do somthing with buf
> >>if len( buf ) < 1024:
> >>break
> >>
> >> rc = p.wait()
>
> >
> > For extra points is there a way to speed up the p.stdout.read(bufsize)
> > ?
>
> Its unlikely that is the problem, most likely you are reading all of the
> 2MB OS pipe buffer and then having to wait for the programme you are
> calling to produce some more output.
>
> Before trying to speed things up be sure to test with real work being
> done to the output you recieve.
>
> If its still slow and you have multiple cores/processors then you will
> need to put you read loop in a thread to speed it up.
>
> --
> Rob.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
--- Get your facts first, then you can distort them as you please.--
-- 
http://mail.python.org/mailman/listinfo/python-list


parsing a file for analysis

2011-02-25 Thread Rita
I have a large text (4GB) which I am parsing.

I am reading the file to collect stats on certain items.

My approach has been simple,

for row in open(file):
  if "INFO" in row:
line=row.split()
user=line[0]
host=line[1]
__time=line[2]
...

I was wondering if there is a framework or a better algorithm to read such
as large file and collect it stats according to content. Also, are there any
libraries, data structures or functions which can be helpful? I was told
about 'collections' container.  Here are some stats I am trying to get:

*Number of unique users
*Break down each user's visit according to time, t0 to t1
*what user came from what host.
*what time had the most users?

(There are about 15 different things I want to query)

I understand most of these are redundant but it would be nice to have a
framework or even a object oriented way of doing this instead of loading it
into a database.


Any thoughts or ideas?




--- Get your facts first, then you can distort them as you please.--
-- 
http://mail.python.org/mailman/listinfo/python-list