Re: How to print non-printable chars??

2011-08-18 Thread coldpizza
On Aug 13, 7:59 am, Julio Cesar Rodriguez Cruz
 wrote:
> Hi all,
> If I open an .exe file in any text editor I get lot of odd chars,
> what I want is to know how to output those chars if I have the hexadecimal
> code. I found out how to do the reverse process with the quopri module,
>
> i.e.:>>> import quopri
> >>> quopri.encodestring('ñè ')
> '=F1=E8=18'
> >>> quopri.decodestring('=F1=E8=18')
>
> '\xf1\xe8\x18'
>
> but how to do the reverse? ...gived '\xf1\xe8\x18', print 'ñè '
>
> any tips?
> thanks
> Julio Cesar

In a web/html environment or in broken ascii-only consoles like the
one on windows, I use the following hack:

print your_unicode_string.encode('us-ascii','xmlcharrefreplace')

This will print unicode chars using pure ASCII symbols which will
display correctly in a web browser and are more readable in a console
than unicode escapes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to use ssh-agent in windows in python?

2019-05-27 Thread coldpizza
example code for doing it in pure python: 
http://code.activestate.com/recipes/576810-copy-files-over-ssh-using-paramiko/
-- 
https://mail.python.org/mailman/listinfo/python-list


sqlite3 db update extremely slow

2007-07-16 Thread coldpizza
I am trying to fill a sqlite3 database with records, and to this end I
have written a class that creates the db, the table and adds rows to
the table.

The problem is that the updating process is *extremely* slow, and
occasionally I get the message "database locked".

I tried removing "self.con.commit()" in the add_record method, but
then nothing is saved in the db. I don't know whether this has
anything to do with it, but I have found no option to enable
autocommit.

This is the class that I am using:

class sqliteDB(object):
"Wrapper for SQLite methods"
def __init__(self, db_file="sqlite3.db"):
'Intialize SQLite database, sqlite_db_init("db_file_name.db")'
print 'SQLite db init: ', db_file
self.con = sqlite3.connect(db_file)
self.cur = self.con.cursor()

def create_table(self, table):
"create table (table_name)"

query ='CREATE TABLE %s (hword VARCHAR(256) PRIMARY KEY,
definition TEXT)' % table
try:
self.cur.execute(query)
self.con.commit()
except Exception, e:
print e

def add_record (self, table, headWord, definition):

try:
self.cur.execute('INSERT INTO ' + table + '(hword,
definition) VALUES(?, ?)', (headWord, definition))
self.con.commit()
except Exception,  e:
print e

And this is the actual code that I use to write to the db file:

db = sqliteDB()
db.create_table("table_name")

for k, v in myData:
  db.add_record(table, k,v)

This works extremely slow (~10KB of data per second) and takes ages to
complete even with small files. Where did I go wrong?

Would it be faster (or possible) to import a text file to sqlite using
something like the mysql's command
LOAD DATA INFILE "myfile.csv"...?

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


Re: sqlite3 db update extremely slow

2007-07-16 Thread coldpizza
Thanks a lot, Roel, adding a single commit() at the end did solve the
speed problem.

Another question is do I have to explicitly close the DB connection,
or is it automatically garbage collected? Is it Ok to no have any
cleanup code?

Another question would be how to define the encoding for newly added
records?
And how do set the encoding for the retrieved records? Is it always
utf-8 by default?

On Jul 16, 11:21 pm, Roel Schroeven <[EMAIL PROTECTED]>
wrote:
> coldpizza schreef:
>
> > I am trying to fill a sqlite3 database with records, and to this end I
> > have written a class that creates the db, the table and adds rows to
> > the table.
>
> > The problem is that the updating process is *extremely* slow, and
> > occasionally I get the message "database locked".
>
> > I tried removing "self.con.commit()" in the add_record method, but
> > then nothing is saved in the db. I don't know whether this has
> > anything to do with it, but I have found no option to enable
> > autocommit.
>
> Remove self.con.commit() from add_record(), and do it once after all
> records are added.
>
> The reason that the process is slow with a commit after every INSERT is
> that sqlite syncs the inserted data to disk before it continues.
>
> --
> If I have been able to see further, it was only because I stood
> on the shoulders of giants.  -- Isaac Newton
>
> Roel Schroeven


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


database persistence with mysql, sqlite

2007-09-22 Thread coldpizza
Hi,

I want to run a database query and then display the first 10 records
on a web page. Then I want to be able to click the 'Next' link on the
page to show the next 10 records, and so on.

My question is how to implement paging, i.e. the 'Next/Prev' NN
records without reestablishing a database connection every time I
click Next/Prev? Is it at all possible with cgi/mod_python?

For example, in a NON-web environment, with sqlite3 and most other
modules, I can establish a database connection once, get a cursor
object on which I run a single 'SELECT * FROM TABLE' statement and
then use cursor.fetchmany(NN) as many times as there are still results
left from the initial query.

How do I do the same for the web? I am not using any high-level
framework. I am looking for a solution at the level of cgi or
mod_python (Python Server Pages under Apache). To call
cursor.fetchmany(NN) over and over I need to pass a handle to the
database connection but how do I keep a reference to the cursor object
across pages? I use mysql and sqlite3 as databases, and I am looking
for an approach that would work with both database types (one at a
time). So far I have successfully used the following modules for
database access: sqlite3, mysqld, and pyodbc.

So far, with mysql I use 'SELECT * FROM TABLE LIMIT L1, L2' where L1
and  L2 define the range for the 'Next' and 'Previous' commands. I
have to run the query every time a click a 'Next/Prev' link. But I am
not sure that this is the best and most efficient way. I suppose using
CURSOR.FETCHMANY(NN) would probably be faster and nicer but how do I
pass an object reference across pages? Is it possible without any
higher-level libraries?

What would be the proper way to do it on a non-enterprise scale?

Would SqlAlchemy or SqlObject make things easier with regard to
database persistence?

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


Re: database persistence with mysql, sqlite

2007-09-24 Thread coldpizza
On Sep 24, 7:23 am, Lawrence D'Oliveiro <[EMAIL PROTECTED]
central.gen.new_zealand> wrote:
> In message <[EMAIL PROTECTED]>, coldpizza
> wrote:
>
> > So far, with mysql I use 'SELECT * FROM TABLE LIMIT L1, L2' where L1
> > and  L2 define the range for the 'Next' and 'Previous' commands. I
> > have to run the query every time a click a 'Next/Prev' link. But I am
> > not sure that this is the best and most efficient way.

> Try it first, then see what happens. Remember, premature optimization is the
> root of all (programming) evil.

It turned out that the method above ('SELECT * FROM TABLE LIMIT L1,
L2') works ok both with mysql and sqlite3, therefore I have decided to
stick with it until I find something better. With Sqlite3 you are
supposed to use LIMIT 10 OFFSET NN, but it also apparently supports
the mysql syntax (LIMIT NN, 10) for compatibility reasons.

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


How to display unicode with the CGI module?

2007-11-24 Thread coldpizza
Hi!

I am using the built-in Python web server (CGIHTTPServer) to serve
pages via CGI.
The problem I am having is that I get an error while trying to display
Unicode UTF-8 characters via a Python CGI script.

The error goes like this: "UnicodeEncodeError: 'ascii' codec can't
encode character u'\u026a' in position 12: ordinal not in range(128)".

My question is: (1 ) how and (2) where do I set the encoding for the
page?

I have tried adding  but this does not seem to help, as this is an
instruction for the browser, not for the webserver and/or CGI script.

Do I have to set the encoding in the server script? On in the Python
CGI script?

The data that I want to display comes from a sqlite3 database and is
already in Unicode format.

The webserver script looks like this:

[code]
#
import CGIHTTPServer, BaseHTTPServer
httpd=BaseHTTPServer.HTTPServer(('',8080),
CGIHTTPServer.CGIHTTPRequestHandler)
httpd.serve_forever()
#
[/code]

A simplified version of my Python CGI script would be:
[code]
import cgi

print "text/html"
print

print ""
print " "
print   "my UTF8 string: Français 日本語 Español Português Română"
print " "
print ""

[/code]

Where and what do I need to add to these scripts to get proper display
of UTF8 content?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to display unicode with the CGI module?

2007-11-25 Thread coldpizza
> Unicode != UTF-8.
...
>`encode()` method is your friend.

Thanks a lot for help!

I am always confused as to which one to use: encode() or decode(); I
have initially tried decode() and it did not work.

It is funny that encode() and decode() omit the name of the other
encoding (Unicode ucs2?), which makes it far less readable than a
s.recode('ucs2','utf8').

Another wierd thing is that by default Python converts internal
Unicode to ascii. Will it be the same in Py3k? string*.
> Just to expand on this... It helps thinking of "unicode objects" and
> "strings" as seperate types (which they are). So there is no such thing
> like "unicode string" and you always need to think about when to
> encode() your unicode objects. However, this will change in py3k...,
> what's the new rule of thumb?
>
> cheers
>   Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


UTF-8 in basic CGI mode

2008-01-15 Thread coldpizza
Hi,

I have a basic Python CGI web form that shows data from a SQLite3
database. It runs under the built-in CGIWebserver which looks like
this:

[code]
import SimpleHTTPServer
import SocketServer
SocketServer.TCPServer(("",
80),SimpleHTTPServer.SimpleHTTPRequestHandler).serve_forever()
[/code]

The script runs Ok with ANSI characters, but when I try to process non-
ASCII data I get an UnicodeDecodeError exception ('ascii' codec can't
decode byte 0xd0 in position 0: ordinal not in range(128)).

I have added the the 'u' prefix to all my literal strings, and I
_have_ wrapped all my output statements into myString.encode('utf8',
"replace"), but, apparently the UnicodeDecodeError exception occurs
because of a string that I get back to the script through
cgi.FieldStorage( ).

I.e. I have the lines:
form = cgi.FieldStorage( )
word= form['word']
which retrieve the 'word' value from a GET request.

I am using this 'word' variable like this:

print u'' % (word)

and apparently this causes exceptions with non-ASCII strings.

I've also tried this:
print u'' %
(word.encode('utf8'))
but I still get the same UnicodeDecodeError..

What is the general good practice for working with UTF8?

The standard Python CGI documentation has nothing on character sets.

It looks insane to have to explicitly wrap every string
with .encode('utf8'), but even this does not work.

Could the problem be related to the encoding of the string returned by
the cgi.fieldstorage()? My page is using UTF-8 encoding.

What would be encoding for the data that comes from the browser after
the form is submitted?

Why does Python always try to use 'ascii'? I have checked all my
strings and they are prefixed with 'u'. I have also tried replacing
print statements with
sys.stdout.write (DATA.encode('utf8'))
but this did not help.

Any clues?

Thanks in advance.


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


UTF-8 in basic CGI mode

2008-01-15 Thread coldpizza
Hi,

I have a basic Python CGI web form that shows data from a SQLite3
database. It runs under the built-in CGIWebserver which looks
something like
this:

[code]
from BaseHTTPServer import HTTPServer
from CGIHTTPServer  import CGIHTTPRequestHandler
HTTPServer("8000", CGIHTTPRequestHandler).serve_forever( )
[/code]

The script runs Ok with ANSI characters, but when I try to process
non-
ASCII data I get an UnicodeDecodeError exception ('ascii' codec can't
decode byte 0xd0 in position 0: ordinal not in range(128)).

I have added the the 'u' prefix to all my literal strings, and I
_have_ wrapped all my output statements into myString.encode('utf8',
"replace"), but, apparently the UnicodeDecodeError exception occurs
because of a string that I get back to the script through
cgi.FieldStorage( ).

I.e. I have the lines:
form = cgi.FieldStorage( )
word= form['word']
which retrieve the 'word' value from a GET request.

I am using this 'word' variable like this:

print u'' % (word)

and apparently this causes exceptions with non-ASCII strings.

I've also tried this:
print u'' %
(word.encode('utf8'))
but I still get the same UnicodeDecodeError..

What is the general good practice for working with UTF8?

The standard Python CGI documentation has nothing on character sets.

It looks insane to have to explicitly wrap every string
with .encode('utf8'), but even this does not work.

Could the problem be related to the encoding of the string returned by
the cgi.fieldstorage()? My page is using UTF-8 encoding.

What would be encoding for the data that comes from the browser after
the form is submitted?

Why does Python always try to use 'ascii'? I have checked all my
strings and they are prefixed with 'u'. I have also tried replacing
print statements with
sys.stdout.write (DATA.encode('utf8'))
but this did not help.

Any clues?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UTF-8 in basic CGI mode

2008-01-17 Thread coldpizza
Thanks, Sion, that makes sense!

Would it be correct to assume that the encoding of strings retrieved
by FieldStorage() would be the same as the encoding of the submitted
web form (in my case utf-8)?

Funny but I have the same form implemented in PSP (Python Server
Pages), running under Apache with mod_python and it works
transparently with no explicit charset translation required.

On Jan 16, 4:31 pm, Sion Arrowsmith <[EMAIL PROTECTED]>
wrote:
> coldpizza  <[EMAIL PROTECTED]> wrote:
> >I am using this 'word' variable like this:
>
> >print u'''''' % (word)
>
> >and apparently this causes exceptions with non-ASCII strings.
>
> >I've also tried this:
> >print u'''''' %
> >(word.encode('utf8'))
> >but I still get the same UnicodeDecodeError..
>
> Your 'word' is a byte string (presumably UTF8 encoded). When python
> is asked to insert a byte string into a unicode string (as you are
> doing with the % operator, but the same applies to concatenation
> with the + operator) it attempts to convert the byte string into
> unicode. And the default encoding is 'ascii', and the ascii codec
> takes a very strict view about what an ASCII character is -- and
> that is that only characters below 128 are ASCII.
>
> To get it to work, you need to *decode* word. It is already UTF8
> (or something) encoded. Under most circumstances, use encode() to
> turn unicode strings to byte strings, and decode() to go in the
> other direction.
>
> --
> \S -- [EMAIL PROTECTED] --http://www.chaos.org.uk/~sion/
>    "Frankly I have no feelings towards penguins one way or the other"
>         -- Arthur C. Clarke
>    her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump

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


Re: How to detect a remote webpage is accessible? (in HTTP)

2008-01-18 Thread coldpizza
I suppose that if the file is really big and you don't need to read
all of it
then instead of f.readlines() you could use f.read(256) to read just
the first 256 bytes.

On Jan 18, 7:28 am, Astan Chee <[EMAIL PROTECTED]> wrote:
> How about:
>
> import socket, urllib2
>
> timeout = 10
> socket.setdefaulttimeout(timeout)
> try:
> auth_handler = urllib2.HTTPBasicAuthHandler()
> opener = urllib2.build_opener(auth_handler) #this used if we need
> authentication
> urllib2.install_opener(opener)
> req = urllib2.Request('http://website.com')
> f = urllib2.urlopen(req)
> notes= f.readlines()
> f.close()
> print "Everything is ok"
> except IOError, r:
> p = str(r)
> if re.search(r'urlopen error timed out',p):
> print "Web page timed out"
>
> You'll need to set up the timeout to whatever duration your website
> takes to load.
> Cheers
> Astan
>
>
>
> ?? wrote:
> > Howdy, all,
> >      I want to use python to detect the accessibility of website.
> > Currently, I use urllib
> > to obtain the remote webpage, and see whether it fails. But the problem is 
> > that
> > the webpage may be very large; it takes too long time. Certainly, it
> > is no need to download
> > the entire page. Could you give me a good and fast solution?
> >     Thank you.
> > --
> > ShenLei

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


py3k feature proposal: field auto-assignment in constructors

2008-01-27 Thread coldpizza
There is a pattern that occurs fairly often in constructors in Python
and other OOP languages.

Let's take an example:

class Server(object):
def __init__(self, host, port, protocol, bufsize, timeout):
self.host = host
self.port = port
self.protocol = protocol
self.bufsize = bufsize
self.maxthreads = maxthreads
self.timeout = timeout

Imho, in the class above the assignment to instance fields does not
contain much programming logic and therefore can be safely 'abstracted
away' by the language itself with a syntax which would look something
like this:

class Server(object):
def __init__(self, @host, @port, @protocol, @bufsize, @timeout):
pass

This would be equivalent to the first example above, yet it does not
obfuscate the code in any way. Or does it? It does look much cleaner
to me.

Of course, the ampersand is just an arbitrary choice and might have
bad connotations for those who read it as 'take address of' but @ has
some allusion to delegates which maybe is ok.

I am not an experienced programmer and I am not sure if this is
necessarily a good idea, so I wanted to get some feedback from more
experienced Pythonistas before submitting it elsewhere.


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


Re: py3k feature proposal: field auto-assignment in constructors

2008-01-29 Thread coldpizza
Hi,

I appreciate everyone's feedback on the topic.

Having reflected on what has been said here, I now realize that
creating more complexity is not the way to go. I would rather favor
something that relies on existing language features, something like
the default keyword argument assignment in functions.

This is probably stupid but as a noob I would have liked something
like:
def __init__( self. = host, self. = port, self. = timeout, message =
"Connected."):
pass

This is probably even more preposterous than @host, @port, but to me
it would make more sense.

I suppose the subject has exhausted itself and I am not going to
follow it up. If anyone is interested in taking it on, then please do.

Best,
coldpizza


On Jan 29, 6:01 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> "André" <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
> |Here's a version that
> |1. does not require new syntax
> |2. does not *necessarily* override the "_" prefix convention
>
> 'self_' is way too bulky and intrusive.  Putting '_' at the end of the word
> is nearly as easy to detect and conflicts with no convention I know of.
>
> tjr

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


Re: best set of modules for web automation without javascript

2009-02-14 Thread coldpizza
You should have a look at twill:
   http://twill.idyll.org

It seems to be no longer maintained, but will probably do most of what
you expect. And it is built on top of mechanize.


On Feb 13, 4:04 pm, News123  wrote:
> Hi,
>
> I'd like to do some web automation with python 2.5
> - https:
> - a cookiejar
> - some forms to be filled in
>
> what is the best set of modules.
>
> As far as I understood, there is httplib, but it seems (if I understood
> well) to be incoompatible with cookielib
>
> I'm a newcomer to webautomation with python and would be thankful for
> good suggestions.
>
> I used so far perl with LWP::UserAgent HTTP::Cookies and some module (I
> forgot the name) to handle parsing and filling in Forms.
>
> thanks in advance for any pointers opinions
>
> N

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


Re: best set of modules for web automation without javascript

2009-02-14 Thread coldpizza
And btw, Selenium scripts can be exported to Python and run under
Selenium Remote Control server.

I'd say this is the most flexible and advanced way to do webtesting,
since you can have a single script that runs with many browsers
(opera, firefox, ie, etc), and on many platforms.

And combined with HTMLTestRunner you can get beautiful test reports.

On Feb 13, 8:01 pm, Matias Surdi  wrote:
> You should give a look to Selenium. It's great.
>
> http://www.openqa.org
>
>
>
> News123 wrote:
> > Hi,
>
> > I'd like to do some web automation with python 2.5
> > - https:
> > - a cookiejar
> > - some forms to be filled in
>
> > what is the best set of modules.
>
> > As far as I understood, there is httplib, but it seems (if I understood
> > well) to be incoompatible with cookielib
>
> > I'm a newcomer to webautomation with python and would be thankful for
> > good suggestions.
>
> > I used so far perl with LWP::UserAgent HTTP::Cookies and some module (I
> > forgot the name) to handle parsing and filling in Forms.
>
> > thanks in advance for any pointers opinions
>
> > N
> > --
> >http://mail.python.org/mailman/listinfo/python-list

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


Tkinter: stopping a background thread on demand

2009-02-19 Thread coldpizza
I am writing a Tk GUI for a console script. I start a background
thread and pass it a callback function which writes debug info to a
Text widget in the main Tk loop.

I tried to find what is the established way to cleanly abort a child
thread when the user clicks the Stop button, but apparently Python
does not allow the parent process to explicitly stop a child thread.
Also I could not figure out how a parent can send a signal for a child
to stop and let it cleanup and exit cleanly.

I finally figured out a solution which was to set a 'TERMINATE' flag
on the `func_dict` property of the callback function, and then check
for the flag in the child module, but I still have doubts that this is
the proper way to do this sort of thing.

This works fine but it looks more like a dirty hack to me so my
question is: what is the proper way to send a signal to a child thread
to gracefully terminate, assuming the user decided to cancel an
operation?

from Tkinter import *
import threading

root = Tk()

class ConverterThread(threading.Thread):
def __init__(self, source, target, callbackFunc):
threading.Thread.__init__(self, name='converterThread')
self.infile = srcName
self.outfile = destName
self.callbackFunc = callbackFunc
def run(self):
import myconverter
myconverter.convert(self.infile, self.outfile,
self.callbackFunc)

def stopConversion(event=None):
global job
if (job and job.isAlive()):
callbackFunc.func_dict['TERMINATE'] = True
job = None

def updateLogCallback(data=None):
log.insert(END, str(data))
log.see('end')

job = ConverterThread(src='file1', dest='file2, updateLogCallback)
job.start()

stopBtn = Button(root, text="Stop", command=stopConversion)
stopBtn.pack()
log = Text(root)
root.mainloop()


And the callbackFunc in myConverter.py looks like this:

def printCallback(data):
if (callback):
callback(data)
if callback.func_dict['TERMINATE'] == True:
clean_up()
sys.exit()
else:
print data


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


Re: Newbie request assistance....Python - PAMIE - Java

2009-02-20 Thread coldpizza
This is not a Pamie issue. Pamie can only see the HTML part of the
page. Any object embedded in the page using the  or 
tags is not accessible to the browser, and the browser has no idea
what is inside those objects - it simply passes control to the
corresponding plugin, such as Java, Flash, ActiveX, etc.

To script user interaction with an applet you will probably need some
expensive commercial software such as QuickTestPro or SilkTest.

Pamie is IE-only and does not seem to be actively developed. If you
need a good and robust HTML testing framework look into Selenium,
especially Selenium Remote Control, which can be used with a number of
languages including Python.

As for embedded stuff like Flash or Java applets, there is no freeware
tool that I am aware of which would be able to work with both HTML and
stuff like Flash or Java applets.

Best,
cp

On Feb 19, 10:50 pm, frankrentef  wrote:
> Greetings all...
>
> Newbie here to the Python world.  I've written some basic script with
> the purpose of automating testing of an application via Python /
> Pamie.  I've had pretty good success until a spot I'm testing displays
> a Java pop up.  I need to have Pamie access the fields in the window
> (i.e. add a value and activate the "enter" button.)  Can someone
> assist.
>
> Some of the code I have currently is as follows...when the script I've
> written gets to the end the java window pops up automaticallyI
> don't understand how to interface with it.
>
> THNX
>
> ie.textBoxSet('_ctl0_ContentPlaceHolder1_Bocarc1_txtMAX', '5000.00')
> time.sleep(2)
> ie.textBoxSet('_ctl0_ContentPlaceHolder1_Bocarc1_txtMIN', '0')
> time.sleep(2)
> ie.buttonClick('_ctl0_ContentPlaceHolder1_Bocarc1_ckCheckMicr')
> time.sleep(2)
> ie.buttonClick('_ctl0_ContentPlaceHolder1_Bocarc1_ckCheckMicr')
> ie.timesleep(2)
> ie.textBoxSet('_ctl0_ContentPlaceHolder1_Bocarc1_txtMaxMicrRejects',
> '1')
> time.sleep(2)
> ie.buttonClick('_ctl0_ContentPlaceHolder1_arc1_btnUpdate')
> time.sleep2

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


Re: FTP libs for Python?

2009-02-20 Thread coldpizza
Why don't you just use Curl? It does a dozen of protocols including
SFTP. And if the command line version is not enough for you then there
are Python bindings for Curl.

On Feb 20, 4:22 pm, Thomas Allen  wrote:
> I'm interested in writing a script to ease deployment of minor changes
> on some websites here, and it would involve some SFTP transfers. Do
> you know of good alternatives to ftplib, which is relatively low-
> level?
>
> Thomas

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


'Hidden Features of Python'

2008-10-17 Thread coldpizza
Having read through the link below I finally managed to grasp some
concepts that I only read about in the docs but never got to really
understand. Maybe it will be helpful for people like myself who are
not yet fully comfortable with some of Python's `hidden' features.

http://stackoverflow.com/questions/101268/hidden-features-of-python
--
http://mail.python.org/mailman/listinfo/python-list


Re: 'Hidden Features of Python'

2008-10-17 Thread coldpizza
If you are using and IDE, such as Eclipse, PyScripter, etc, then CTR
+click on 'this' should do the trick.
In ipython you can do 'import this' and then type 'this??' Or if you
are *not* lazy, you could try locating the file in the Python tree.

> import this
> # btw look at this module's source :)
>
> I don't see what I'm supposed to get from that.  If I'm supposed to  
> see the magic (and explanation) be examining the source for the 'this'  
> module, well, I don't see how I can do that either.  Can someone who  
> gets this share a clue?
>
> Thanks,
> - Joe

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


Re: How to use python to register a service (an existing .exe file)

2010-03-02 Thread coldpizza
instsrv.exe does not come with Windows by default, but I guess it
should be possible to add a service using the win32 built-in `sc`
command line tool.

Try `sc create` from a console.

The app you want to install as a service will still have to be
compliant with the win32 service interface, otherwise it will throw an
error, although the app will still be started.

On Feb 16, 2:10 am, News123  wrote:
> Hi,
>
> Is there a python way to register new windows services.
>
> I am aware of the
> instsrv.exe program, which can be used to install services.
> I could use subprocess.Popen to call
>
> instsrv.exe "service_name" program.exe
>
> but wondered, whether there's already an existing function.
>
> Thans in advance and bye
>
> N

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


Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-28 Thread coldpizza
On Nov 24, 11:08 pm, Raymond Hettinger  wrote:
> I'm writing-up more guidance on how to use super() and would like to
> point at some real-world Python examples of cooperative multiple
> inheritance.
>
> Google searches take me to old papers for C++ and Eiffel, but that
> don't seem to be relevant to most Python programmers (i.e. a
> WalkingMenu example where a submenu is both a Entry in a Menu and a
> Menu itself).  Another published example is in a graphic library where
> some widgets inherit GraphicalFeature methods such as location, size
> and NestingGroupingFeatures such as finding parents, siblings, and
> children.  I don't find either of those examples compelling because
> there is no particular reason that they would have to have overlapping
> method names.
>
> So far, the only situation I can find where method names necessarily
> overlap is for the basics like __init__(), close(), flush(), and
> save() where multiple parents need to have their own initialization
> and finalization.
>
> If you guys know of good examples, I would appreciate a link or a
> recap.
>
> Thanks,
>
> Raymond

Did you try google code search? It is *not* the same as google code
hosting.
The site is http://www.google.com/codesearch and you can select Python
in the 'language' dropdown.
-- 
http://mail.python.org/mailman/listinfo/python-list


convert Unicode filenames to good-looking ASCII

2010-05-06 Thread coldpizza
Hello,

I need to convert accented unicode chars in some audio files to
similarly-looking ascii chars. Looks like the following code seems to
work on windows:

import os
import sys
import glob

EXT = '*.*'

lst_uni = glob.glob(unicode(EXT))

os.system('chcp 437')
lst_asci = glob.glob(EXT)
print sys.stdout.encoding

for i in range(len(lst_asci)):
try:
os.rename(lst_uni[i], lst_asci[i])
except Exception as e:
print e

On windows it converts most of the accented chars from the latin1
encoding. This does not work in Linux since it uses 'chcp'.

The questions are (1) *why* does it work on windows, and (2) what is
the proper and portable way to convert unicode characters to similarly
looking plain ascii chars?

That is how to properly do this kind of conversion?
 ü  > u
 é  > e
 â  > a
 ä  > a
 à  > a
 á  > a
 ç  > c
 ê  > e
 ë  > e
 è  > e

Is there any other way apart from creating my own char replacement
table?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: convert Unicode filenames to good-looking ASCII

2010-05-06 Thread coldpizza
Cool! Thanks to both Iliya and Peter!

On May 6, 7:34 pm, Peter Otten <__pete...@web.de> wrote:
> coldpizza wrote:
> > Hello,
>
> > I need to convert accented unicode chars in some audio files to
> > similarly-looking ascii chars. Looks like the following code seems to
> > work on windows:
>
> > import os
> > import sys
> > import glob
>
> > EXT = '*.*'
>
> > lst_uni = glob.glob(unicode(EXT))
>
> > os.system('chcp 437')
> > lst_asci = glob.glob(EXT)
> > print sys.stdout.encoding
>
> > for i in range(len(lst_asci)):
> >     try:
> >         os.rename(lst_uni[i], lst_asci[i])
> >     except Exception as e:
> >         print e
>
> > On windows it converts most of the accented chars from the latin1
> > encoding. This does not work in Linux since it uses 'chcp'.
>
> > The questions are (1) *why* does it work on windows, and (2) what is
> > the proper and portable way to convert unicode characters to similarly
> > looking plain ascii chars?
>
> > That is how to properly do this kind of conversion?
> >  ü  > u
> >  é  > e
> >  â  > a
> >  ä  > a
> >  à  > a
> >  á  > a
> >  ç  > c
> >  ê  > e
> >  ë  > e
> >  è  > e
>
> > Is there any other way apart from creating my own char replacement
> > table?
> >>> from unicodedata import normalize
> >>> s = u"""ü  > u
>
> ...  é  > e
> ...  â  > a
> ...  ä  > a
> ...  à  > a
> ...  á  > a
> ...  ç  > c
> ...  ê  > e
> ...  ë  > e
> ...  è  > e
> ... """>>> from unicodedata import normalize
> >>> print normalize("NFD", s).encode("ascii", "ignore")
>
> u  > u
>  e  > e
>  a  > a
>  a  > a
>  a  > a
>  a  > a
>  c  > c
>  e  > e
>  e  > e
>  e  > e

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