Re: [Tutor] python access of usb for winxp

2008-04-10 Thread Michael Langford
Libusb on windows, which pyusb depends on, is somewhat lacking the last time
I tried. Seems like libusb on win is abandoned.

--Michael

On Thu, Apr 10, 2008 at 2:42 PM, govind goyal <[EMAIL PROTECTED]> wrote:

> Hello,
> I want to retreive data to and fro USB device attached/connected to my
> WinXP PC.
> Is there any module or library available in python?
> I came across "pyusb" and downloaded some packages but I am not getting
> how
> to use or install those packages.Win
> Can anybody help me out in above stuffs?
> All help will be highly appreciated.
>
> Thanks and Best Regards,
>  --Govind Goyal
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python, CGI and CSS

2008-04-10 Thread Alex Krycek
Thank you all for your help. I've finally figured it out. I took people's
suggestions and typed in the path for the CSS file into my browser. Well, I
received an internal service error. When I checked the error log, I had
received the following:

[Thu Apr 10 20:38:47 2008] [error] [client ::1] (8)Exec format error: exec
of '/usr/local/apache2/cgi-bin/style1.css' failed

If I understand this correctly, Apache was apparently trying to execute my
CSS file. So I moved the CSS file into my /~username/Sites folder (I'm on a
Mac), changed the href link in my Python script, and finally my CSS rules
were applied to the selected XHTML. I read somewhere that it's not a good
idea to have anything other than scripts in one's cgi-bin anyways. Thanks
again!



On Thu, Apr 10, 2008 at 3:22 PM, Kent Johnson <[EMAIL PROTECTED]> wrote:

> Alex Krycek wrote:
>
> > Eric,
> >
> > I'm sorry, I never actually managed to get any stylesheets to work with
> > my cgi scripts. The scripts that did work are just simple HTML.
> >
>
> Where are the css files that work located? What URL is used to fetch them?
> If you put the css for your cgi into the same location and fetch with a
> similar URL it should work.
>
> Kent
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python, CGI and CSS

2008-04-10 Thread Curtis Adkins
It seems that your link to the stylesheet is just pointing to the wrong
place.

Like the others said, check to make sure you are pointing to the right
place of the CSS file by typing it into the web browser.  If you use the
link you gave : "http://localhost/cgi-bin/style1.css"; what shows up?
Anything?  From this link it says that your style sheet is in your
cgi-bin directory.  

On Thu, 2008-04-10 at 14:22 -0600, Alex Krycek wrote:
> Hi,
> 
> I've looked all over the internet but have not found an answer to my
> question. How do I apply an external stylesheet to the XHTML in a
> Python script? I tried to include the standard " type='text/css' href='style1.css' />"" in with the rest of the printed
> XHTML. But that didn't work. I changed the href attribute to
> "/style1.css", then to "../style1.css" and finally to
> "http://localhost/cgi-bin/style1.css";, all failed attempts. Just so
> you know, both sets of permissions for these two files have been set
> to 755. I tried other cgi scripts (still residing in the cgi-bin) and
> they did work. I checked the error log, and this is what I'm getting:
> (2)No such file or directory.
> 
> When I took both files out of my cgi-bin, as a test, the CSS rules
> were
> implemented. I'm not sure why it stops working when located in the cgi-bin 
> folder.
> 
> Thanks!
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Conventions for code snippets for debugging and testing?

2008-04-10 Thread Alan Gauld
"Robert Kirkpatrick" <[EMAIL PROTECTED]> wrote

> The use case I'm dealing with right now is to query the SVN commits 
> for a
> weekly period and report on each user for that time period.  If I'm 
> testing
> though, I only want to cycle through a few users, not all of them.

You could pass the values in as command line arguments which
are otherwise defaulted. Then to run the debug version create
a shell alias or even a shell script with the debig values and
another with the production values.

Or if there are several values store the values in a config file and
pass the name of the config file in as an argument.

Or you could use environment variables to point to the config file.
Or you could store the values as individual environment vars and
have a batch file set the values prior to debugging and another
to reset them for production.

Lots of options.

There is nothing Python specific about any of this its how debug
environments have been set up for decades.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SQLite LIKE question

2008-04-10 Thread Alan Gauld

"Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote

> I'm reading a text file into an in-memory pysqlite table.
> When I do a SELECT on the table, I get a 'u' in front of
> each returned row eg.
>
> (u'QB VII',)

The u is not part of the data its Python telling you that
the string is Unicode.

> The second problem is that I'm using the LIKE operator
> to match a pattern against a string but am getting garbage
> results.

Can you be more specidic?
Can you post the statement and the 'garbage'?

> for row in con.execute(
"SELECT  FROM  WHERE  LIKE '%q%' limit 25"):

Is thios the actual string or have you put the placemarkers ( 
etc)
in just for the post? You do realise that the things inside <> are 
intended
to be replaced with the actual values from your database. Thus a
realistic string would look like

"SELECT Name FROM Person WHERE Name LIKE '%q%"

Which would return all Names with q in them.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python, CGI and CSS

2008-04-10 Thread Alan Gauld

"Alex Krycek" <[EMAIL PROTECTED]> wrote


> I did look into CGI tutorials, but they didn't use Python code. They 
> used
> something like:
> start_html(-title => $title,
> -head => style({type => 'text/css'} )

That looks like Perl. Try the CGI tutorial on the Python web site.

That would be a good start.

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python, CGI and CSS

2008-04-10 Thread Alan Gauld

"Alex Krycek" <[EMAIL PROTECTED]> wrote

> How do I apply an external stylesheet to the XHTML in a Python
> script?

Python doesn't really do anything with CSS that is handled by the 
browser.
All Python can do is insert the correct HTML into the server response
to the browser.

> I tried to include the standard " type='text/css' href='style1.css' />"" in with the rest of the 
> printed
> XHTML. But that didn't work.

What if anything happened?
And how did you test it?
Did the CSS file actually exist in the location specified?

> I changed the href attribute to "/style1.css",
> then to "../style1.css" and finally to 
> "http://localhost/cgi-bin/style1.css";,
> all failed attempts. Just so you know, both sets of permissions for 
> these
> two files have been set to 755. I tried other cgi scripts (still 
> residing in
> the cgi-bin) and they did work. I checked the error log, and this is 
> what
> I'm getting: (2)No such file or directory.

So it says the file doesn't exist. Have you double checked that the
css file is in the same folder as the CGI script? When you say you
tried other CGI scripts and they worked, what does that mean?
That they loaded the same CSS file?

If its only the CSS that isn't working you can presumably save
the web page from the browser as HTML? What does the HTML
look like? Is it what you expected? What path is it specifying?

> When I took both files out of my cgi-bin, as a test, the CSS rules 
> were
> implemented. I'm not sure why it stops working when located in the
> cgi-bin folder.

Ok, You obviously understand that paragraph but to the rest of
us it is wholly ambiguous. When you took which files out of cgi-bin?
In what way did they work? What was different exactly that
constituted "working"? What is the "it" that stops working?
The system the CSS, the CGI script? All of the above?

Sorry, but I need a bit more precision in the description to
understand what tyhe problem is. It might help if you can
include a directory tree listing of the significant files - cgi and 
css.
Also the section of the generated HTML that imports the CSS file.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python access of usb for winxp

2008-04-10 Thread Alan Gauld

"govind goyal" <[EMAIL PROTECTED]> wrote

> I want to retreive data to and fro USB device attached/connected to 
> my
> WinXP PC.

It depends what kind of device it is.
If it is a drive or flash card you can use the normal file access
functions. If it is a printer or scanner then the usual APIs for
those devices will work.

You should only need to go down to the raw USB interface
for very specialised devfices, and in that case you will need
to understand enough about USB to use pyUSB

So what kind of devices are they? And how would you
access those devices if they weren't USB? Try that first!


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] SQLite LIKE question

2008-04-10 Thread Dinesh B Vadhia
I'm reading a text file into an in-memory pysqlite table.  When I do a SELECT 
on the table, I get a 'u' in front of each returned row eg.

> (u'QB VII',)
> (u'Quackser Fortune Has a Cousin in the Bronx',)

I've checked the data being INSERT'ed into the table and it has no 'u'.

The second problem is that I'm using the LIKE operator to match a pattern 
against a string but am getting garbage results.  For example, looking for the 
characters q='dog' in each string the SELECT statement is as follows:

for row in con.execute("SELECT  FROM  WHERE  LIKE '%q%' 
limit 25"):
print row

This doesn't work and I've tried other combinations without luck!  Any thoughts 
on the correct syntax for the LIKE?

Dinesh
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Conventions for code snippets for debugging and testing?

2008-04-10 Thread Kent Johnson
Eric Walstad wrote:

> I'd do something like this:
> 
> from settings import DEBUG
> 
> def my_user_list()
> # assumes long_list is already populated (db, file, etc)
> if DEBUG:
> return long_list[:5]
> else:
> return long_list
> 
> def process(user):
> # do the work on the user here
> pass
> 
> def main():
> # ...
> [process(user) for user in my_user_list()]
> 
> The idea is to encapsulate the retrieval of the user list and let that
> encapsulation hide the DEBUG logic.  It could be done with a function,
> like above, or with a MyUserList class.

I would encapsulate the retrieval but not the DEBUG. My preference would 
be to have a separate main() in a test module that trims the user list. 
Then the DEBUG setting is not needed at all.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Conventions for code snippets for debugging and testing?

2008-04-10 Thread Kent Johnson
Robert Kirkpatrick wrote:
> Hi All,
> 
> Just wondering if there are any basic conventions for including code
> snippets that are for testing / debugging only?
> 
> For example, you could set a boolean variable called DEBUG,

That is pretty common, with a boolean or an integer (for levels of debug 
info).

> The use case I'm dealing with right now is to query the SVN commits for a
> weekly period and report on each user for that time period.  If I'm testing
> though, I only want to cycle through a few users, not all of them.

I would look at the structure of your code. Maybe there is a function 
that just runs one user that you could use for testing, or perhaps you 
could pass in a number that is a limit on how many users to process.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python, CGI and CSS

2008-04-10 Thread Kent Johnson
Alex Krycek wrote:
> Eric,
> 
> I'm sorry, I never actually managed to get any stylesheets to work with 
> my cgi scripts. The scripts that did work are just simple HTML. 

Where are the css files that work located? What URL is used to fetch 
them? If you put the css for your cgi into the same location and fetch 
with a similar URL it should work.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Conventions for code snippets for debugging and testing?

2008-04-10 Thread Eric Walstad
Hi Robert

On Thu, Apr 10, 2008 at 1:34 PM, Robert Kirkpatrick <[EMAIL PROTECTED]> wrote:
> Hi All,
>
>  Just wondering if there are any basic conventions for including code
>  snippets that are for testing / debugging only?
>
>  For example, you could set a boolean variable called DEBUG, then have
>  snippets of code like:
>
>  if DEBUG:
> do stuff
>  else:
> do otherstuff
I'd do something like this:

from settings import DEBUG

def my_user_list()
# assumes long_list is already populated (db, file, etc)
if DEBUG:
return long_list[:5]
else:
return long_list

def process(user):
# do the work on the user here
pass

def main():
# ...
[process(user) for user in my_user_list()]

The idea is to encapsulate the retrieval of the user list and let that
encapsulation hide the DEBUG logic.  It could be done with a function,
like above, or with a MyUserList class.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python, CGI and CSS

2008-04-10 Thread Eric Walstad
Hey Alex,
On Thu, Apr 10, 2008 at 1:43 PM, Alex Krycek <[EMAIL PROTECTED]> wrote:
> Eric,
>
> I'm sorry, I never actually managed to get any stylesheets to work with my
> cgi scripts. The scripts that did work are just simple HTML. I'm using
> Apache 2.2.8 on a Mac OS X 10.4.11 system.
If I understand your problem, you are expecting to see your stylesheet
loaded but that is not happening.  If that's what you want to fix,
then I suggest you fix it in as simple a test case as possible.  Try
browsing directly to the css file with your web browser.  When you
have your web server configured correctly you should see the contents
of your css displayed in the web browser.  If you can't view your css
file in your browser, then send us the apache log file line that shows
the failed GET request and we can go from there.

Keep the scripting and cgi stuff out of the equation until you get this working.
Also, reread the apache FAQ.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Conventions for code snippets for debugging and testing?

2008-04-10 Thread Robert Kirkpatrick
Hi All,

Just wondering if there are any basic conventions for including code
snippets that are for testing / debugging only?

For example, you could set a boolean variable called DEBUG, then have
snippets of code like:

if DEBUG:
do stuff
else:
do otherstuff

The use case I'm dealing with right now is to query the SVN commits for a
weekly period and report on each user for that time period.  If I'm testing
though, I only want to cycle through a few users, not all of them.

I'm thinking there has to be something slicker than that but maybe not...

Thoughts?

Rob

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python, CGI and CSS

2008-04-10 Thread Alex Krycek
Eric,

I'm sorry, I never actually managed to get any stylesheets to work with my
cgi scripts. The scripts that did work are just simple HTML. I'm using
Apache 2.2.8 on a Mac OS X 10.4.11 system. When I get home I'll definitely
look up the log file and paste it here. I'll also have to fool around with
the permissions and httpd.conf file.

I did look into CGI tutorials, but they didn't use Python code. They used
something like:
start_html(-title => $title,
-head => style({type => 'text/css'} )

Thanks for the suggestions though.



On 4/10/08, Eric Walstad <[EMAIL PROTECTED]> wrote:
>
> Hi Alex,
>
> On Thu, Apr 10, 2008 at 1:22 PM, Alex Krycek <[EMAIL PROTECTED]>
> wrote:
> > Hi,
> >
> > I've looked all over the internet but have not found an answer to my
> > question. How do I apply an external stylesheet to the XHTML in a Python
> > script? I tried to include the standard " > type='text/css' href='style1.css' />"" in with the rest of the printed
> > XHTML.
>
> Try writing your html file by hand, tweaking the href and/or server
> config and/or file permissions by hand until it *does* work.  Once you
> have a working reference point, then make your Python script duplicate
> what you know works.
>
>
>
> > I
> > tried other cgi scripts (still residing in the cgi-bin) and they did
> work.
>
> View the HTML source of these working CGI scripts to see what the css
> link tag looks like.  How does it differ from the css link tag output
> of your Python script?
>
>
>
> > I
> > checked the error log, and this is what I'm getting: (2)No such file or
> > directory.
>
> Paste the actual log file line here.
>
>
>
> > When I took both files out of my cgi-bin, as a test, the CSS rules were
> > implemented. I'm not sure why it stops working when located in the
> cgi-bin
> > folder.
>
> It feels like a permissions problem or a configuration problem with
> your web server.
>
>
> What webserver are you using?
> Have you followed any of the CGI tutorials?
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python, CGI and CSS

2008-04-10 Thread Eric Walstad
Hi Alex,
On Thu, Apr 10, 2008 at 1:22 PM, Alex Krycek <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've looked all over the internet but have not found an answer to my
> question. How do I apply an external stylesheet to the XHTML in a Python
> script? I tried to include the standard " type='text/css' href='style1.css' />"" in with the rest of the printed
> XHTML.
Try writing your html file by hand, tweaking the href and/or server
config and/or file permissions by hand until it *does* work.  Once you
have a working reference point, then make your Python script duplicate
what you know works.


> I
> tried other cgi scripts (still residing in the cgi-bin) and they did work.
View the HTML source of these working CGI scripts to see what the css
link tag looks like.  How does it differ from the css link tag output
of your Python script?


> I
> checked the error log, and this is what I'm getting: (2)No such file or
> directory.
Paste the actual log file line here.


> When I took both files out of my cgi-bin, as a test, the CSS rules were
> implemented. I'm not sure why it stops working when located in the cgi-bin
> folder.
It feels like a permissions problem or a configuration problem with
your web server.


What webserver are you using?
Have you followed any of the CGI tutorials?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python, CGI and CSS

2008-04-10 Thread Steve Willoughby
On Thu, Apr 10, 2008 at 02:22:47PM -0600, Alex Krycek wrote:
> Hi,
> 
> I've looked all over the internet but have not found an answer to my
> question. How do I apply an external stylesheet to the XHTML in a Python
> script? I tried to include the standard " type='text/css' href='style1.css' />"" in with the rest of the printed
> XHTML. But that didn't work. I changed the href attribute to "/style1.css",
> then to "../style1.css" and finally to "http://localhost/cgi-bin/style1.css";,
> all failed attempts. Just so you know, both sets of permissions for these
> two files have been set to 755. I tried other cgi scripts (still residing in
> the cgi-bin) and they did work. I checked the error log, and this is what
> I'm getting: (2)No such file or directory.
> 
> When I took both files out of my cgi-bin, as a test, the CSS rules were
> implemented. I'm not sure why it stops working when located in the
> cgi-bin folder.

It's likely your web server is set up to *execute* (not deliver as text) 
files in your cgi-bin directory.


> 
> Thanks!

> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


-- 
Steve Willoughby|  Using billion-dollar satellites
[EMAIL PROTECTED]   |  to hunt for Tupperware.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python, CGI and CSS

2008-04-10 Thread Alex Krycek
Hi,

I've looked all over the internet but have not found an answer to my
question. How do I apply an external stylesheet to the XHTML in a Python
script? I tried to include the standard """ in with the rest of the printed
XHTML. But that didn't work. I changed the href attribute to "/style1.css",
then to "../style1.css" and finally to "http://localhost/cgi-bin/style1.css";,
all failed attempts. Just so you know, both sets of permissions for these
two files have been set to 755. I tried other cgi scripts (still residing in
the cgi-bin) and they did work. I checked the error log, and this is what
I'm getting: (2)No such file or directory.

When I took both files out of my cgi-bin, as a test, the CSS rules were
implemented. I'm not sure why it stops working when located in the
cgi-bin folder.

Thanks!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] queries from the web & random number

2008-04-10 Thread linuxian iandsd
i was wondering if there was there any means of sending this number to the
script thru the web.
I mean have the script run from cron & i can remotely access the image read
the code & enter the code in a form to be "submitted to my script" or
another script i don't mind as long as it gets to final destination.

I have already setup webpage with form & i have the image on it.

i guess i have to setup some sort of server /client application to do this
...
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Copy script

2008-04-10 Thread Tony Cappellini
>>Of course they do - they can use input redirection just like Unix.
Oh,-I have forgotten about that.
But why use clunky batch language when you can use Python? After all, he did
post this to the python list.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python access of usb for winxp

2008-04-10 Thread govind goyal
Hello,
I want to retreive data to and fro USB device attached/connected to my
WinXP PC.
Is there any module or library available in python?
I came across "pyusb" and downloaded some packages but I am not getting how
to use or install those packages.
Can anybody help me out in above stuffs?
All help will be highly appreciated.

Thanks and Best Regards,
 --Govind Goyal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] queries from the web & random number

2008-04-10 Thread linuxian iandsd
I modified old script - added

get_img=urllib2.urlopen('http://website.com/jcaptcha.jpg')
> secret_img=open('/home/iandsd/secret_img.jpg','wb')
> secret_img.write(get_img.read())
> secret_img.close()
>

and then to add the value to the dictionary :

values['captcha']=raw_input("Enter the number you see on picture  :")
>

data=urllib.urlencode(values)
> req=urllib2.Request(url, data, headers)
>
>
& i m on the road again.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Graphs in Python

2008-04-10 Thread Kent Johnson
Sanhita Mallick wrote:
> Hi.
> 
> I am a newbie to Python. I am trying to implement a
> Python code for graph manipulation. My graphs are
> about 200-500 nodes big. Excepting for the short basic
> graph implementation info on Python.org, where can I
> find more in depth info about how to express graphs in
> python, and how to use them in a  code?

Many pointers here:
http://www.velocityreviews.com/forums/t355467-tree-and-graph-structures-in-python.html

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Graphs in Python

2008-04-10 Thread Sanhita Mallick
Hi.

I am a newbie to Python. I am trying to implement a
Python code for graph manipulation. My graphs are
about 200-500 nodes big. Excepting for the short basic
graph implementation info on Python.org, where can I
find more in depth info about how to express graphs in
python, and how to use them in a  code?

Also, does anyone know of a easy way of creating the
dictionary for python for a 500-node graph, without
typing each and every node? I found some application
that recognize dot file Graphviz - but I am looking
for a program that can let me "draw" a graph and then
generate the lists automatically from the drawing.

Thanks.
-SM
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] queries from the web & random number

2008-04-10 Thread Marc Tompkins
On Thu, Apr 10, 2008 at 9:14 AM, linuxian iandsd <[EMAIL PROTECTED]>
wrote:

> I have been used to making queries to websites automatically & analizing
> the results. a few minutes ago ... i can no longer do that
> now a website is protected by a ramdom number that i have to enter before
> i can login.
> its a picture with numbers on it that i have to type in in the
> authentication form before login in.
>

I don't have any insight on solving your problem - but what you're talking
about is called CAPTCHA, for Completely Automated Public Turing Test to Tell
Computers and Humans Apart.  It'll probably be easier to communicate if you
call it by name - everybody will know what you mean.


-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] queries from the web & random number

2008-04-10 Thread Alan Gauld

"linuxian iandsd" <[EMAIL PROTECTED]> wrote

> now a website is protected by a ramdom number that i have to enter 
> before i
> can login.its a picture with numbers on it that i have to type in in 
> the
> authentication form before login in.

This is added to web sites to specifically stop people screen
scraping the site. Sometimes to stop comparison sites from
stealing trade, other times to force users to see sponsors
adverts.

If you ignore the owners/authors wishes you will make yourself
unpopular and very unlikely to get much support from them in
future. Worth considering before you deliberately set out to
circumvent their wishes

> now i need to at least be able to download this very first picture 
> that has
> the random number on it to my hard disk so that i can look at it & 
> feed my
> script with that number automatically. is that possible ?

Almost cerainly since its just an embedded image, although what
you do once you've grabbed it is another matter... If its present it
to the user for manual input not too bad, if its trying to auto-read
the text out of the uimage, then good luck!


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Text editing

2008-04-10 Thread Alan Gauld

"Michael Schultz" <[EMAIL PROTECTED]> wrote

> Hello everyone. I'm looking to build a cross-platform "writer's 
> assistant",
> and I figured my first step would be to re-invent the wheel, er I 
> mean built
> a simple rich-text editor as a base.
>
> I'm trying to figure out the simplest way to do so, and figured I'd 
> ask if
> anyone knew some good resources that give examples I can study?

Look at the code for IDLE.
Look at the Scintilla widget and the Ala Mode code in wxPython.

I assume you want to use a GUI toolkit.

Fuinally decide whether you want a full GUI WYSIWYG editing
interface or a command driven one (ala vi or emacs C- mode).
The latter is esier to build but less popular with modern users.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Copy script

2008-04-10 Thread Alan Gauld
"Tony Cappellini" <[EMAIL PROTECTED]> wrote

>>>I don;t see how the input file relates to the pdf files?
>>>Which part of the pdf file does the input numbers refer to?
>
> Kent, I believe the text file contains the name

Actually that was me :-)

> The problem with the Windows console commands is I don't believe 
> they have
> the ability to read files for input.

Of course they do - they can use input redirection just like Unix.
But the FOR /F option I mentioned is explicitly for iterating over
the contents of a text file. And of course you can use backticks(`)
to TYPE a file into a command, in place of a file list, say.

The XP command line tools are much better than the early DOS
stuff - although still nowhere near to Unix shells.

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] queries from the web & random number

2008-04-10 Thread linuxian iandsd
I have been used to making queries to websites automatically & analizing the
results. a few minutes ago ... i can no longer do that
now a website is protected by a ramdom number that i have to enter before i
can login.
its a picture with numbers on it that i have to type in in the
authentication form before login in.

i use urllib2.install_opener(opener) to keep the kookies & work on other
pages of the website using response=urllib2.urlopen(req)

now i need to at least be able to download this very first picture that has
the random number on it to my hard disk so that i can look at it & feed my
script with that number automatically. is that possible ? its a picture
thats generated on the fly  i guess & it comes only at the login page.

i mean launch script, look at the picture, feed taht number to my script
from the prompt & hit enter & it would go on as usual.

thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Searching through large number of string items

2008-04-10 Thread Kent Johnson
Dinesh B Vadhia wrote:
> Ignore the 'adjacent items' remark.   The rest is correct ie. looking 
> for all strings containing a substring x.

Perhaps this would help:
http://hkn.eecs.berkeley.edu/~dyoo/python/suffix_trees/

A SubstringDict that maps each string to itself would do exactly what 
you want. I have no idea what the performance would be...

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Text editing

2008-04-10 Thread Kent Johnson
Michael Schultz wrote:
> Hello everyone. I'm looking to build a cross-platform "writer's 
> assistant", and I figured my first step would be to re-invent the wheel, 
> er I mean built a simple rich-text editor as a base.
> 
> I'm trying to figure out the simplest way to do so, and figured I'd ask 
> if anyone knew some good resources that give examples I can study?

wxPython includes a rich text control, see the wx demos.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Searching through large number of string items

2008-04-10 Thread Greg Graham
One idea has to do with the fact that there are only 26 (assuming Latin
alphabet) possible first letters, so I would try splitting up the list
of 10,000 into 26 lists in a dictionary indexed by the first letter.
Just doing that is a big reduction of your search space. That way you
won't be doing the same search every time for a particular first letter.
It might even be worthwhile to split each of those into 26 sublists
based on the second letter. Now you've chopped up your 10,000 words into
676 lists, each of which might be small enough to send to the client
without further searching. (Too bad you won't have an even distribution
across all letters. Then each list would only have 15 words in it.)

 

You could also try using SQLite. I'm using right now in a Django
application, and I'm very happy with the setup and performance,
especially for read operations. With Django, I'm using their ORM, which
is quite nice, so I'm not doing any SQL directly. I think there can be
problems with SQLite when you attempt concurrent writes, but you
wouldn't have that.

 

It's hard to predict which would perform better, a tailor made domain
specific solution written in Python, or a general purpose in-memory
database written in C. I would start with which ever direction you are
most comfortable, and if you can't get satisfactory performance, try the
other route.

 

Greg

 

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Dinesh B Vadhia
Sent: Thursday, April 10, 2008 8:13 AM
To: tutor@python.org
Subject: Re: [Tutor] Searching through large number of string items

 

The 10,000 string items are sorted.

 

The way the autocomplete works is that when a user enters a char eg.
'f', the 'f' is sent to the server and returns strings with the char
'f'.  You can limit the number of items sent back to the browser (say,
limit to between 15 and 100).  The string items containing 'f' are
displayed.  The user can then enter another char eg. 'a' to make 'fa'.
The autocomplete plugin will search the cache to find all items
containing 'fa' but may need to go back to the server to collect others.
And, so on.  Equally, the user could backspace the 'f' and enter 'k'.
The 'k' will be sent to the server to find strings containing 'k', and
so on.

 

One way to solve this is with linear search which as you rightly pointed
out has horrible performance (and it has!).  I'll try the binary search
and let you know.  I'll also look at the trie structure.

 

An alternative is to create an in-memory SQLite database of the string
items.  Any thoughts on that?

 

Dinesh

 

 

- Original Message - 

From: Kent Johnson   

To: Dinesh B Vadhia   

Cc: tutor@python.org 

Sent: Thursday, April 10, 2008 5:20 AM

Subject: Re: [Tutor] List comprehensions

 

Dinesh B Vadhia wrote:
> Kent
>  
> I'm using a Javascript autocomplete plugin for an online web 
> application/service.  Each time a user inputs a character, the
character 
> is sent to the backend Python program which searches for the character

> in a list of >10,000 string items.  Once it finds the character, the 
> backend will return that string and N other adjacent string items
where 
> N can vary from 20 to 150.  Each string item is sent back to the JS in

> separate print statements.  Hence, the for loop.

Ok, this sounds a little closer to a real spec. What kind of search are 
you doing? Do you really just search for individual characters or are 
you looking for the entire string entered so far as a prefix? Is the 
list of 10,000 items sorted? Can it be?

You need to look at your real problem and find an appropriate data 
structure, rather than showing us what you think is the solution and 
asking how to make it faster.

For example, if what you have a sorted list of strings and you want to 
find the first string that starts with a given prefix and return the N 
adjacent strings, you could use the bisect module to do a binary search 
rather than a linear search. Binary search of 10,000 items will take 
13-14 comparisons to find the correct location. Your linear search will 
take an average of 5,000 comparisons.

You might also want to use a trie structure though I'm not sure if that 
will let you find adjacent items.
http://www.cs.mcgill.ca/~cs251/OldCourses/1997/topic7/
http://jtauber.com/blog/2005/02/10/updated_python_trie_implementation/

> I haven't done any profiling yet as we are still building the system
but 
> it seemed sensible that replacing the for loop with a built-in would 
> help.  Maybe not?

Not. An algorithm with poor "big O" performance should be *replaced*, 
not optimized.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Searching through large number of string items

2008-04-10 Thread Dinesh B Vadhia
Ignore the 'adjacent items' remark.   The rest is correct ie. looking for all 
strings containing a substring x.


- Original Message - 
From: Kent Johnson 
To: Dinesh B Vadhia 
Cc: tutor@python.org 
Sent: Thursday, April 10, 2008 6:32 AM
Subject: Re: [Tutor] Searching through large number of string items


Dinesh B Vadhia wrote:
> The 10,000 string items are sorted.
>  
> The way the autocomplete works is that when a user enters a char eg. 
> 'f', the 'f' is sent to the server and returns strings with the char 
> 'f'. 

If it is all strings containing 'f' (not all strings starting with 'f') 
then the binary search will not work. A database might work better for that.

You can get all strings containing some substring x with
[ item for item in list if x in item ]

Of course that is back to linear search. You mentioned before that you 
want to also show adjacent items? I don't know how to do that with a 
database either.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Text editing

2008-04-10 Thread Michael Schultz
Hello everyone. I'm looking to build a cross-platform "writer's assistant",
and I figured my first step would be to re-invent the wheel, er I mean built
a simple rich-text editor as a base.

I'm trying to figure out the simplest way to do so, and figured I'd ask if
anyone knew some good resources that give examples I can study?

Thanks a lot!
~Mike
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Copy script

2008-04-10 Thread Tony Cappellini
Message: 7
Date: Thu, 10 Apr 2008 01:46:49 +0100
From: "Alan Gauld" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Copy script
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
   reply-type=original

>>I don;t see how the input file relates to the pdf files?
>>Which part of the pdf file does the input numbers refer to?

Kent, I believe the text file contains the name of the text files the author
wants to copy
The problem with the Windows console commands is I don't believe they have
the ability to read files for input.

Que
Here is some code that should get you started.
I don't see the name of the destination directory in your email, so you will
have to edit the variable 'destpath' in the code below
Indenting is likely to get changed during posting, so be aware of that.

import shutil
import os

sourceDir=''

for line in open('input.txt'):
if not sourceDir and ':' in line:
sourceDir = line[line.find(':')-1:]

if 'pdf' in line.lower():
filename = line.split(' ')[-1]
sourcePath = os.path.join(sourceDir, filename)
shutil.copyfile(sourcePath, destPath)
print'\nCopying %s' % sourcePath


print'\nCopy done'
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Searching through large number of string items

2008-04-10 Thread Kent Johnson
Dinesh B Vadhia wrote:
> The 10,000 string items are sorted.
>  
> The way the autocomplete works is that when a user enters a char eg. 
> 'f', the 'f' is sent to the server and returns strings with the char 
> 'f'. 

If it is all strings containing 'f' (not all strings starting with 'f') 
then the binary search will not work. A database might work better for that.

You can get all strings containing some substring x with
[ item for item in list if x in item ]

Of course that is back to linear search. You mentioned before that you 
want to also show adjacent items? I don't know how to do that with a 
database either.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List comprehensions

2008-04-10 Thread bob gailer
Dinesh B Vadhia wrote:
> Kent
>  
> I'm using a Javascript autocomplete plugin for an online web 
> application/service.  Each time a user inputs a character, the 
> character is sent to the backend Python program which searches for the 
> character in a list of >10,000 string items. Once it finds the 
> character, the backend will return that string and N other adjacent 
> string items where N can vary from 20 to 150.
So if I had these strings

"ape", "bee", "cat", dog", "eel", "fly", "gnu", "hex", "imp", "jut", 
"kit", "lox"

and N were 2 and the user entered "g" the program finds "dog" and sends 
back "cat", dog", "eel".

OK so far or not?

The user then enters "y", the program finds "fly" and sends back "eel", 
"fly", "gnu".

OK so far or not?

The user then enters "x", the program finds no match and sends back what??

>  Each string item is sent back to the JS in separate print statements. 
IIRC you don't need separate print statements. Just put \n between the 
strings and print one big string.
> Hence, the for loop.
>  
> Now, N = 20 to 150 is not a lot (for a for loop) but this process is 
> performed each time the user enters a character.  Plus, there will be 
> thousands (possibly more) users at a time.  There is also the 
> searching of the >10,000 string items using the entered character.  
> All of this adds up in terms of performance.
>  
> I haven't done any profiling yet as we are still building the system 
> but it seemed sensible that replacing the for loop with a built-in 
> would help.  Maybe not?
>  
> Hope that helps.
>  
> Dinesh
>  
>  
> - Original Message -
> *From:* Kent Johnson 
> *To:* Dinesh B Vadhia 
> *Cc:* tutor@python.org 
> *Sent:* Wednesday, April 09, 2008 1:48 PM
> *Subject:* Re: [Tutor] List comprehensions
>
> Dinesh B Vadhia wrote:
> > Here is a for loop operating on a list of string items:
> > 
> > data = ["string 1", "string 2", "string 3", "string 4", "string 5",
> > "string 6", "string 7", "string 8", "string 9", "string 10", "string 
> 11"]
> > 
> > result = ""
> > for item in data:
> > result =  item
> > print result
> > 
> > I want to replace the for loop with another structure to improve
> > performance (as the data list will contain >10,000 string items].  At
> > each iteration of the for loop the result is printed (in fact, the
> > result is sent from the server to a browser one result line at a time)
>
> Any savings you have from optimizing this loop will be completely
> swamped by the network time. Why do you think this is a bottleneck?
>
> You could use
> [ sys.stdout.write(some operation on item) for item in data ]
>
> but I consider this bad style and I seriously doubt you will see any
> difference in performance.
>
> > The for loop will be called continuously and this is another reason to
> > look for a potentially better structure preferably a built-in.
>
> What do you mean 'called continuously'?
>
> Kent
> 
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>   


-- 
Bob Gailer
919-636-4239 Chapel Hill, NC

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Searching through large number of string items

2008-04-10 Thread Dinesh B Vadhia
The 10,000 string items are sorted.

The way the autocomplete works is that when a user enters a char eg. 'f', the 
'f' is sent to the server and returns strings with the char 'f'.  You can limit 
the number of items sent back to the browser (say, limit to between 15 and 
100).  The string items containing 'f' are displayed.  The user can then enter 
another char eg. 'a' to make 'fa'.  The autocomplete plugin will search the 
cache to find all items containing 'fa' but may need to go back to the server 
to collect others.  And, so on.  Equally, the user could backspace the 'f' and 
enter 'k'.  The 'k' will be sent to the server to find strings containing 'k', 
and so on.

One way to solve this is with linear search which as you rightly pointed out 
has horrible performance (and it has!).  I'll try the binary search and let you 
know.  I'll also look at the trie structure.

An alternative is to create an in-memory SQLite database of the string items.  
Any thoughts on that?

Dinesh


- Original Message - 
From: Kent Johnson 
To: Dinesh B Vadhia 
Cc: tutor@python.org 
Sent: Thursday, April 10, 2008 5:20 AM
Subject: Re: [Tutor] List comprehensions


Dinesh B Vadhia wrote:
> Kent
>  
> I'm using a Javascript autocomplete plugin for an online web 
> application/service.  Each time a user inputs a character, the character 
> is sent to the backend Python program which searches for the character 
> in a list of >10,000 string items.  Once it finds the character, the 
> backend will return that string and N other adjacent string items where 
> N can vary from 20 to 150.  Each string item is sent back to the JS in 
> separate print statements.  Hence, the for loop.

Ok, this sounds a little closer to a real spec. What kind of search are 
you doing? Do you really just search for individual characters or are 
you looking for the entire string entered so far as a prefix? Is the 
list of 10,000 items sorted? Can it be?

You need to look at your real problem and find an appropriate data 
structure, rather than showing us what you think is the solution and 
asking how to make it faster.

For example, if what you have a sorted list of strings and you want to 
find the first string that starts with a given prefix and return the N 
adjacent strings, you could use the bisect module to do a binary search 
rather than a linear search. Binary search of 10,000 items will take 
13-14 comparisons to find the correct location. Your linear search will 
take an average of 5,000 comparisons.

You might also want to use a trie structure though I'm not sure if that 
will let you find adjacent items.
http://www.cs.mcgill.ca/~cs251/OldCourses/1997/topic7/
http://jtauber.com/blog/2005/02/10/updated_python_trie_implementation/

> I haven't done any profiling yet as we are still building the system but 
> it seemed sensible that replacing the for loop with a built-in would 
> help.  Maybe not?

Not. An algorithm with poor "big O" performance should be *replaced*, 
not optimized.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List comprehensions

2008-04-10 Thread Kent Johnson
Alan Gauld wrote:

> One possibility is that the javascript fetches the list back on the
> first few characters and caches it on the browser

Here is an autocomplete widget I use that can do exactly that:
http://www.dyve.net/jquery/?autocomplete

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List comprehensions

2008-04-10 Thread Alan Gauld
"Kent Johnson" <[EMAIL PROTECTED]> wrote

>> application/service.  Each time a user inputs a character, the 
>> character
>> is sent to the backend Python program which searches for the 
>> character
>> in a list of >10,000 string items.  Once it finds the character, 
>> the
>> backend will return that string and N other adjacent string items 
>> where
>> N can vary from 20 to 150.  Each string item is sent back to the JS 
>> in
>> separate print statements.  Hence, the for loop.
>
> You need to look at your real problem and find an appropriate data
> structure, rather than showing us what you think is the solution and
> asking how to make it faster.

One possibility is that the javascript fetches the list back on the
first few characters and caches it on the browser, it can then do
the search locally and only go back to the server if the user
deletes enough characters to invalidate the cache. That would
make a big difference to the overall speed by eliminating several
network lookups. I am assuming the server lookup list does not
change significantly over the duration of a form submission?

Alan G 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List comprehensions

2008-04-10 Thread Kent Johnson
Dinesh B Vadhia wrote:
> Kent
>  
> I'm using a Javascript autocomplete plugin for an online web 
> application/service.  Each time a user inputs a character, the character 
> is sent to the backend Python program which searches for the character 
> in a list of >10,000 string items.  Once it finds the character, the 
> backend will return that string and N other adjacent string items where 
> N can vary from 20 to 150.  Each string item is sent back to the JS in 
> separate print statements.  Hence, the for loop.

Ok, this sounds a little closer to a real spec. What kind of search are 
you doing? Do you really just search for individual characters or are 
you looking for the entire string entered so far as a prefix? Is the 
list of 10,000 items sorted? Can it be?

You need to look at your real problem and find an appropriate data 
structure, rather than showing us what you think is the solution and 
asking how to make it faster.

For example, if what you have a sorted list of strings and you want to 
find the first string that starts with a given prefix and return the N 
adjacent strings, you could use the bisect module to do a binary search 
rather than a linear search. Binary search of 10,000 items will take 
13-14 comparisons to find the correct location. Your linear search will 
take an average of 5,000 comparisons.

You might also want to use a trie structure though I'm not sure if that 
will let you find adjacent items.
http://www.cs.mcgill.ca/~cs251/OldCourses/1997/topic7/
http://jtauber.com/blog/2005/02/10/updated_python_trie_implementation/

> I haven't done any profiling yet as we are still building the system but 
> it seemed sensible that replacing the for loop with a built-in would 
> help.  Maybe not?

Not. An algorithm with poor "big O" performance should be *replaced*, 
not optimized.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List comprehensions

2008-04-10 Thread W W
My guess, though I'm not sure, is that google uses hashes...

why? Because they're a *ahem* load faster than loops, and the reason
is they replace the repetitive nature of a loop by using some type of
formula. Exactly /how/ this is implemented, I'm not sure.

A simple example of the speed difference:

11 * 1 =  11
The program spent 0.000810146331787 seconds.
11 * 1 =  11
The program spent 6.19888305664e-05 seconds.
(btw, that means .06... )

The difference? The first was a loop:

  1 from time import time
  2 start_time = time()
  3
  4 x = 0
  5 while x < 11:
  6 x +=1
  7
  8 print "11 * 1 = ", x
  9
 10 end_time = time()
 11 print "The program spent", end_time - start_time, "seconds."

And the second, a algebraic statement

 14 start_time = time()
 15
 16 x = 11 / 1
 17 print "11 * 1 = ", x
 18
 19 end_time = time()
 20 print "The program spent", end_time - start_time, "seconds."

It would be simple to replace the 11 with a variable supplied by
something like variable = int(raw_input("Enter a number: "))
and you would come out with similar output.

That's basically the reason a dictionary finds dictionary["foo"]
faster than a for loop: the key, "foo", is transformed into some value
(As I understand it, the hashtable refers to some memory location, i.e
0x08f or some such), and there, sitting in that location, is the value
for the key "foo".

so rather than comparing each value a list, it would be like having
some formula to grab that value.

I hope this wasn't too confusing, and if anyone has any corrections or
clarifications, feel free to muck about.

But yeah, a hash is probably the way you want to go (from what I know)
-Wayne

On Thu, Apr 10, 2008 at 5:03 AM, linuxian iandsd <[EMAIL PROTECTED]> wrote:
> also if you need to go for 2 results I propose you use filters &
> interactive menus which will help you tailor the query to the users desires
> & thus limit the query results.
>
> ___
>  Tutor maillist  -  Tutor@python.org
>  http://mail.python.org/mailman/listinfo/tutor
>
>



-- 
To be considered stupid and to be told so is more painful than being
called gluttonous, mendacious, violent, lascivious, lazy, cowardly:
every weakness, every vice, has found its defenders, its rhetoric, its
ennoblement and exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List comprehensions

2008-04-10 Thread linuxian iandsd
i think you are using ajax ... which undoubdetly uses an sql database since
its based on queries run from whithin the application in the browser
whithout the need for refreshing the page ... i would suggest you try
serching internet for something like  "google autocomplete feature" & i
guess the queries are also no that long they have a limit of the results ...
for example not more than 20 results per query.

than said there would be no loop. just a query (with a limit of 20 rersults)
each time a use inputs a character.

hope this helps.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List comprehensions

2008-04-10 Thread linuxian iandsd
also if you need to go for 2 results I propose you use filters &
interactive menus which will help you tailor the query to the users desires
& thus limit the query results.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Copy script

2008-04-10 Thread linuxian iandsd
could you do a : "dir /b" inside this directory just so that we can know the
real file names.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Doubts about Pylint

2008-04-10 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote

>>A = 8
>>az = A
>>
>>It may well be happy since A is a constant and the variable
>>is being assigned the constant rather than the literal.
> 
> Thanks, Alan, but I tried your
> 
> A = 8
> az = A
> 
> and got the same complaint about az.

OK, In that case its probably the fact its global as suggested by 
Jerry and the regex approach being used is assuming all globals 
should be functions or classes or Consts...

The bottom line is that its highlighting something the author 
thought might indicate a problem not necessarily a valid error.

I once used a version of C lint that had a -v flag that printed an 
explanatory message along with each reported error, it would 
be nice if pyLint did the same - a nice wee project for anyone 
that's feeling bored and wants to contribute something to the 
Python/Opensource community maybe?!!! :-)

Alan G

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List comprehensions

2008-04-10 Thread Alan Gauld

"Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote i

> I'm using a Javascript autocomplete plugin for an online 
> web application/service.  Each time a user inputs a character, 
> the character is sent to the backend Python program which 
> searches for the character in a list of >10,000 string items.  

Eeek! 
That will be incredibly slow over any kind of network 
other than fast gigabit! try doing a ping from the client to the 
server. If it over the internet you will be lucky to get less that 
100ms, over a fast LAN it might be around 30ms. 
Add in the transmission time for your data 
- (ie 150*ave string length*10/average bandwidth) 
That network delay will swamp any optimisation of a for loop.

It is likely to come out around 10ms so your total delay 
between each character becomes 40-110ms or a maximum 
typing rate of 9-25 characters per second. The latter will feel
slightly clunky but the former will feel very sluggish. And on 
anything less than a good internet connection the rate could 
drop off to around 1 character per second! And anyone using 
a mobile GPRS connection for access would be crippled.

Alan G.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor