Re: [Tutor] can any one help

2010-01-31 Thread Benno Lang
On Mon, Feb 1, 2010 at 6:27 AM, invincible patriot
 wrote:
> thanks for the reply
> i did one question
> i will tel u my progress in another question n then u tel me that what next
> must be done



> thatz the question
> i think that first i woulf take a string 'foobar'
> convert it into a list
> take itz length
> n then do indexing
> and then multiply using for loop
>
> herez my code



> thatz where i am
> now i wana do the indexing of each character so that i use for loop n
> multply each character with 2
>
>
> waiting for ur reply

Hi there,

I think everyone on the list would appreciate it if you wrote in
English, not gibberish.

Regards,
benno.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with random.randint

2010-02-02 Thread Benno Lang
On Wed, Feb 3, 2010 at 12:21 PM, David  wrote:
> Hello list,
>
> I thought this was easy even for me, but I was wrong, I guess.
> Here is what I want to do: take two random numbers between 1 and 99, and put
> them into a list.
>
> import random
> terms =  []
> for i in range(2):
>        terms = random.randint(1, 99)

All you're doing here is assigning an integer value to 'terms', twice.
This assignment means 'terms' is no longer a list, but is now just an
int. What you want is probably:
terms.append (random.randint(1, 99))

> So I tried to change line 4 to the following:
>        terms += random.randint(1, 99)

You can't freely mix types with python operators, i.e. a_list += an_int
But you can use += with 2 ints or 2 lists, so you could do:
terms += [random.randint(1, 99)]
I think using append is much nicer though.

> I understand this error thus: once an int has been placed into the list
> terms, no further int can be added. But: terms is a mutable list, and NOT an
> 'int' object!

The int was never added to the list in the first place, because list
+= int is not something Python understands.

> So here are my questions: what is the problem, and how can I generate two
> random numbers and store them (preferably in a tuple)?

I hope what I wrote above answers the first question.
IIRC tuples are immutable, so you either to create the list first and
then convert it to a tuple:
terms_tuple = tuple(terms)

Or you can create a tuple from the beginning (without a loop):
terms_tuple = (random.randint(1, 99), random.randint(1, 99))

HTH,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "else:" triggering a Syntax Error

2010-02-06 Thread Benno Lang
On Sat, Feb 6, 2010 at 7:56 PM, Stijn .  wrote:
> class Line(): #The class
>     def __init__( self, start_dot, end_dot, width): #init function
>     self.start_dot = start_dot
>     self.surface = pygame.Surface((w, h), SRCALPHA)
>     self.surface.fill((0,0,0,0))
>     self.end_dot = end_dot
>     self.width = width
>     self.selected = 0
>     self.tempX1 = start_dot.x
>     self.tempY1 = start_dot.y
>     self.tempX2 = end_dot.x
>     self.tempY2 = end_dot.y
>     self.visibleTemp1 = self.start_dot.visible
>     self.visibleTemp2 = self.end_dot.visible
>     self.draw = 0
>     self.lastWasMove = 0
>     self.Draw(1)
>     self.rico = 0
>     def Draw ( self, typeOf ): #draw function
>  if ((self.start_dot.x > self.end_dot.x) and (self.start_dot.y !=
> self.end_dot.y)):

(1) Are you sure you want all those superfluous parentheses?

>   self.rico = (self.start_dot.x - self.end_dot.x /
> abs(self.start_dot.y - self.end_dot.y)

(2) You're missing a closing parenthesis.

>  else: #<-causes error message
>   if ((self.start_dot.x < self.end_dot.x and self.start_dot.y !=
> self.end_dot.y))

(3) Don't forget the colon.
(4) See (1)

>    self.rico = (self.end_dot.x - self.start_dot.x) /
> abs(self.start_dot.y - self.end_dot.y)
>   else:
>    self.rico = 0

HTH,
benno.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "else:" triggering a Syntax Error

2010-02-06 Thread Benno Lang
On Sat, Feb 6, 2010 at 9:19 PM, spir  wrote:
> On Sat, 6 Feb 2010 20:18:53 +0900
> Benno Lang  wrote:
>
>> > if ((self.start_dot.x > self.end_dot.x) and (self.start_dot.y !=  
>> > self.end_dot.y)):
>> (1) Are you sure you want all those superfluous parentheses?
>
> @ Benno: I do not find the _inner_ ones superfluous at all...

Fair enough. I do, but obviously with the inner ones it's just a
question of style. Either way, it should be consistent for both ifs.

Cheers,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] html and python

2010-02-10 Thread Benno Lang
On Thu, Feb 11, 2010 at 5:26 AM, Grigor Kolev  wrote:
> I apologize to my question is incorrectly set.
> We have a mail list and we want to do in site a list of all participants
> with their photos and names.
> List with people is saved in the txt file.
> I want to open this file. Take all mail address and to do formating the
> data.
> Then with loop to do parsing all data and to do send in the html.
> I can open and save as plain text document.
> File = file(r'/home/user/test.html', 'w')
> But if I refresh the data every day it by a  slowly.

If you can call scripts when actions occur on the mailing list (e.g.
new subscriber added, user unsubscribes, user details updated, etc),
then you could write a Python script to generate static HTML at that
point. It would probably be less hassle than creating a dynamic web
page.

So then all you have to do is loop through your records and write the
resultant HTML to a file that the web server can read.

HTH,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Coin flip game

2010-02-11 Thread Benno Lang
On Fri, Feb 12, 2010 at 7:15 AM, Jones, Lawrence D
 wrote:
> My code is below. But can someone please explain to me why the following
> variable has to be placed where it is for the code to work? I thought it
> would need to go nearer the start of the code i.e. just before heads = 0,
> tails = 0 etc:
>     coin = random.randrange(2)

If you put this at the start of the code (before the loop), then you
only flip the coin once, and then count that single flip 100 times.
That would work, but wouldn't be a very useful program.

> Also, why does the randrange integer have to be ‘2’? I only discovered this
> worked by complete accident. I tried ‘1’ and ‘0,1’ as my integers but they
> just didn’t work.

See: http://docs.python.org/library/random.html#random.randrange
random.randrange parameters are the same as for range, which you can
learn more about here:
http://docs.python.org/tutorial/controlflow.html#the-range-function

HTH,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] DOWHILE counter

2010-02-16 Thread Benno Lang
On 17 February 2010 12:32,   wrote:
>
> Hi i am trying to write a pseudocode to read an input number and its 15%
> output value. The counter is supposed to process 4 input numbers. Help
> please!!

If it's pseudocode, then you can write a loop however you like.

If you have a Python-related question, please ask it clearly, and be
sure to show what you've done so far.
You should at least read the Python tutorial first, especially the following:
http://docs.python.org/tutorial/introduction.html
http://docs.python.org/tutorial/controlflow.html

HTH,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using and

2010-02-21 Thread Benno Lang
On 21 February 2010 22:44, jim serson  wrote:
> Can anyone tell me if I can have my program check to see if something is
> true the add to count
>
> For example something like
>
> if c_1 and c_2 and c_3 true:
>     count + 1

Your code currently throws the result of the count + 1 expression
away. You probably want this instead:
count = count + 1

> or if I can use it after splitting an input the problem is the input is
> variable so I don't know if I can do such a thing without knowing the input
> ahead of time.

I'm not really sure what you're trying to say here.

HTH,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Strange list behaviour in classes

2010-02-22 Thread Benno Lang
On 23 February 2010 08:16, Benno Lang  wrote:
> class Hand:
>    def __init__(self):
>        self.hand = []

Of course, I meant "class Player"
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Strange list behaviour in classes

2010-02-22 Thread Benno Lang
On 23 February 2010 07:10, C M Caine  wrote:
> Or possibly strange list of object behaviour
>
> IDLE 2.6.2
 class Player():
>        hand = []
>
>
 Colin = Player()
 Alex = Player()

 Players = [Colin, Alex]

 def hands():
>        for player in Players:
>                player.hand.append("A")
>
 hands()

 Colin.hand
> ['A', 'A']
 Alex.hand
> ['A', 'A']
>
> I would have expected hand for each object to be simply ['A']. Why
> does this not occur and how would I implement the behaviour I
> expected/want?

What you're accessing via Colin.hand and Alex.hand is actually
Player.hand, which is a class attribute. You want to set up attributes
on your instance objects instead; the standard way to do this is by
adding an __init__ method to your class:

class Hand:
def __init__(self):
self.hand = []

For more information, I suggest:
http://docs.python.org/tutorial/classes.html

HTH,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What Editori?

2010-02-23 Thread Benno Lang
On 24 February 2010 01:24, Giorgio  wrote:
> what text-editor do you use for python?

I use jEdit, and without a GUI I guess I'd use nano - I'm not the sort
who likes reading manuals in order to use a text editor.
Many years ago when I was on Windows I used to use TextPad. Then I
started using jEdit because it was easy to get going on Windows, Mac,
and Linux. I used to switch between operating systems a lot.

> I've always used kate/nano on Linux and Notepad++/PSPad on Win. Today i've
> installed portablepython to my pendrive, and found pyscripter in that. It's
> nice!
> Do you think it's a good editor? Do you know other names?

Use whatever works for you.

Cheers,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ask

2010-02-23 Thread Benno Lang
On 24 February 2010 12:58, Shurui Liu (Aaron Liu)  wrote:
> This time is not my assignment, I promise.
>
> In python, when we want to list numbers, we use the command "range", like,
> if we want to list integer from 0 to 9, we can write: range(10); if we want
> to list integer from 10 to 29, we can write: range(10,30). I was going to
> show a list of number from 1.0 to 1.9, and I did this in the same way as
> integer: range(1.0,2.0,0.1), but it doesn't work. Can you help me? Thank
> you!

Remember to include your error messages instead of saying "it doesn't work".
It appears that range only supports integers. I did a quick search for
"python float range" and the first link was the following:
http://code.activestate.com/recipes/66472/

HTH,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] strange bidi requirement

2010-02-24 Thread Benno Lang
On 25 February 2010 01:34, rick  wrote:
> I'm trying to write a math quiz program that replicates an old book on
> arithmetic.
>
> when it comes to summing a long column, I need to read the answer from
> the user, one digit at a time.
>
> so, if the answer should be something like
>
> 14238.83
>
> I would need to read the .03, then the .8, and so on.   I figure all
> strings, cast to int  (well, for this example, float).  Would this be
> easier if I learned some GUI programming?   Can it be done at all in
> just console?

If you really want just console, you'll probably need to use curses:
http://docs.python.org/library/curses.html

HTH,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] returning to my quest

2010-02-25 Thread Benno Lang
On 26 February 2010 11:55, Kent Johnson  wrote:
> On Thu, Feb 25, 2010 at 8:59 PM, Kirk Bailey  wrote:
>> for  WEBMAIIL portal to a pop3/smtp email service in my server; centrally
>> hosted or in the laptop is fine, what can people recommend? Without going to
>> IMAP, i want to leave the mail on the server.
>
> I still have no idea what you are asking for. What is a WEBMAIL
> portal? Are you trying to access mail that has a web interface, or
> create a web interface for an existing POP mailbox, or what?
>
> Oh, and what does this have to do with Python?

I'm pretty sure he wants to be able to install some python software on
a server that will provide a web interface for accessing a POP mail
account.
For PHP there's squirrel mail, horde imp, roundcube, etc.

I can't seem to find any at all for Python, at least none that have
been worked on in the last 5 years.
Does anyone else know?

Thanks,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Instantiating a list of strings into a list of classes

2010-03-05 Thread Benno Lang
On 6 March 2010 10:38, Daryl V  wrote:
> I have a csv list of data, of the form:
> plot, utmN83_X, utmN83_Y, plot_radius_m
> Spring1,348545,3589235,13.2
> etc.
> I built a nifty ClassGPSPoint(Xpos,Ypos,plotRadius,workPaths) that eats the
> X&Y positions, the plot radius, and previously instantiated object holding
> all of the appropriate paths definitions to access the LiDAR LAS files.
> I make a nice CSV reader with one line (did I mention I LOVE python?)...
> plotReader =
> csv.reader(open("N:\\GIS_Projects\\095_ForestMetrics\\7_Analyses\\FinalCylinders\\Plots.csv"))
> What I want to do is use the first entry in that row (row[0]) as the
> variable name for the instantiated class.  I'd get an instantiated GPSPoint
> object called 'Spring1' that would yield all my methods and defined values
> (Spring1.pathLASfile, Spring1.perturbXY(), etc)
> Hence, in pseudocode:
> for row in plotReader:
>    row[0] = GPSPoint(row[1],row[2],18.3,workPaths)

All you're doing here is replacing the name stored in row[0] with the
new GPSPoint object.

If I read your description correctly, I think what you're looking for
should behave like this:
# row read from CSV (I assume CSV values are always read as strings)
row = ['Spring1', '348545', '3589235', '13.2']
# what the code you want should do automatically
Spring1 = GPSPoint('348545','3589235','13.2', workPaths)

I don't know how to do that in Python - at a guess it would look
something like (pseudocode):
__module__.vars[row[0]] = GPSPoint(...)
Someone else probably knows how to do that, but I have a fairly strong
feeling that it's the wrong approach to your problem.
When you write your CSV file, each GPSPoint needs to know what its
variable name is, which doesn't seem to make a whole lot of sense. If
you have a set number of objects, then maybe you should just read and
write them in a known order - your program can call them anything it
likes; it won't affect the storage and loading of the data.
Alternatively, if for some reason you really want to associate a name
with each GPSPoint, I would suggest storing the points in a
dictionary, e.g.
points = {}
for row in plotReader:
points[row[0]] = GPSPoint(row[1], row[2], row[3], workPaths)

Then when you need to write to a CSV, the name to go in the first
column is simply the key of that dictionary item.

HTH,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] WSGI / Apache

2010-03-08 Thread Benno Lang
On 5 March 2010 04:37, Giorgio  wrote:
> Hi,
>
> as you all probably know i'm using the Google App Engine platform for my
> python code.
>
> As I learn python i try to understand more and more how GAE works. Today
> i've noticed that all applications on GAE are running on WSGI. A quick
> Google search told me that WSGI is a new standard for web applications,
> developed by python.
>
> So, I decided to try it. With Apache.
>
> I found that Apache has a dedicated mod, mod_wsgi to handle this type of
> requests. But, as I always try to be "platform/daemon indipended" i've
> looked for other solutions. I found WSGIREF that as wsgi.org states
> "includes a threaded HTTP server, a CGI server (for running any WSGI
> application as a CGI script)".
>
> So it seems that wsgiref, that is actually included in python, can "convert"
> my apps to work with a standard CGI interface (in other words, working with
> EVERY server that supports CGI not only with apache and his dedicated mod).
> Can you confirm this?

WSGI is based on CGI, so I imagine that it's not too difficult to have
a wrapper that converts between the protocols. I haven't tried
wsgiref, though.

> Do you have any idea i should use mod_wsgi instead of wsgiref + mod_cgi?

>From your application's perspective, if it talks WSGI it shouldn't
make any difference. But if you're using GAE, what good will it do to
have a local Apache server anyway?

Cheers,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] SQLite error messages

2010-03-09 Thread Benno Lang
On 10 March 2010 11:37, Alan Harris-Reid  wrote:
> Hi there,
>
> I am using the sqlite3 module with Python 3.1, and have some code which goes
> something like as follows...
>
> import sqlite3
> con = sqlite3.connect('MyDatabase.db')
>
> try:
>   execresult = con.execute('INSERT INTO MyTable (field_name) VALUES
> ("MyValue")')
>   con.commit()
> except:
>   con.rollback()
>   If con.execute() fails, nothing is returned, and although the code
> correctly executes the rollback next, I have no idea why, and therefore
> cannot create a suitable error-handler with meaningful messages.
> I notice from the SQLite website that there are error codes, but it looks
> like the sqlite3 module is not reporting them.

Do you mean numerical error codes? Which page on the SQLite website
are you referring to? Certainly the exception contains usable data.
Try something like this:

try:
  execresult = con.execute('INSERT INTO MyTable (field_name) VALUES
("MyValue")')
  con.commit()
except Exception as error:
  print("Didn't work:", error)
  con.rollback()

(I didn't create a table, so I get "Didn't work: no such table: MyTable")

HTH,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] raw_input()

2010-03-15 Thread Benno Lang
On 16 March 2010 08:04, kumar s  wrote:
> %cat mybigfile.rod | python x1.py
> Traceback (most recent call last):
>  File "x1.py", line 2, in 
>    second = raw_input()
> EOFError: EOF when reading a line
>
> How to notify that at EOF break and suppress exception.

try:
second = raw_input()
except EOFError:
# handle error in some way

I would probably supply the file name as an argument rather than
piping into stdin (or allow both methods), but that's up to you.

HTH,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] raw_input()

2010-03-15 Thread Benno Lang
On 16 March 2010 08:28, Steven D'Aprano  wrote:
> On Tue, 16 Mar 2010 10:22:55 am kumar s wrote:
>> thanks Benno.
>>
>> supplying 3.6 GB file is over-kill for the script.
>
> Then supply a smaller file.
>
>
>> This is the reason I chose to input lines on fly.
>
> I don't understand what you are trying to say.

I think he thinks that python is going to read the whole 3.6GB of data
into memory in one hit, rather than using a small amount of memory to
process it line by line. But "for line in datafile" in your code above
uses a generator, right? So I don't think it's a problem - correct me
if I'm wrong.

Thanks,
benno.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python magazine

2010-03-26 Thread Benno Lang
On 27 March 2010 00:33, Lowell Tackett  wrote:
> The Python Magazine people have now got a Twitter site--which includes a 
> perhaps [telling] misspelling.
Obviously that's why they're looking for a chief editor - maybe it's
even a deliberate ploy.

I'm not sure if this affects others, but to me your replies appear
inside the quoted section of your mail, rather than beneath it. Would
you mind writing plain text emails to avoid this issue?

Thanks,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Scraping gov site: site looking for Flash player

2010-04-05 Thread Benno Lang
On 6 April 2010 03:31, Roy Hinkelman  wrote:
> I am using urllib2 to open some government pages, and they have some js
> checking for Flash on my computer.
> Is there a way to show them that I have flash? Or possibly another solution?

>From reading the JavaScript, you should fetch the URL
domain.tld/doc.php?flash=true&doc=2 instead of domain.tld/ as the
first URL.

> var flashPage = "/doc.php?flash=true&doc=2"; // The location of the
> flash movie page

This is the JS that specifies the desired redirect location. You could
open the original URL in a flash-capable browser to work out where to
go as well.

However, if the site is flash-based, you probably won't be able to get
any useful info from it.

HTH,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Best Practice: Subroutines and Loop logic

2009-09-03 Thread Benno Lang
On Fri, Sep 4, 2009 at 3:29 AM, GoodPotatoes wrote:
> Hello,
>
> I am trying to find the best way to do this.  My goal is to only call this
> subroutine only ONCE, and the logic is contingent upon two outputs.
>
> lWords=[...] # List of many, many words
> lData=[...] #list of some words that need to be validated against lWords
>
> #subroutine to search for words, ignore case
> def sub1(foo):
>     pFoo=re.compile(foo,re.I)
>     for word in lWords:
>         if re.search(pFoo,word):
>             return[1,word]
>
> #logic loop
> for word in lData:
>     if word in lWords:
>         continue
>     elif sub1(word)[0]=1:
>         word=sub1(word)[1]  # <--- Here is my question.
>     else:
>         print word " not found.\n"
>
> The subroutine is being run once at the elif statement.  I don't want to run
> it again just to get the [1] value.
>     *Is there any way to capture all of the values returned when it is run
> during the elif statement?

Yes. BTW, since you have a continue, I don't think you need the elif.

>     *Is this actually running twice?

Yes, but it needn't.
I think you would do something like this instead:

if word in lWords:
continue
result = sub1(word):
if result[0] == 1:
word = result[1]
else:
print word " not found.\n"

My apologies if this doesn't make any sense. I'm very much a beginner in Python.

HTH,
benno.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Calling a dictionary entry inside of a function

2009-09-18 Thread Benno Lang
On Sat, Sep 19, 2009 at 9:27 AM, Corey Richardson  wrote:
> I am trying to use a parameter of a function to call a word inside a
> dictionary.
> Here is my code
> wordList = {
>   'Apple' : ["A delicious snack"],
>   'Word' : ["This code is not working..."],
> }
> def define(word):
>   print wordList['Word']
>
>
> When I use define('Apple') it returns ['This code is not working...'].

That's what you asked it to do, but I think you meant print
wordList[word] instead

HTH,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] eazy python question involving functions and parameters

2009-09-20 Thread Benno Lang
On Mon, Sep 21, 2009 at 5:19 AM, daggerdvm  wrote:
>
> assume that  jade2 is a function that expects two  int parameters and returns
> the value of the larger one.
>
> Also assume that four variables,  population1 ,  population2 ,  population3
> , and  population4 have already been defined and associated with  int
> values.
>
> Write an expression (not a statement!) whose value is the largest of
> population1 ,  population2 ,  population3 , and  population4 by calling
> jade2 .

Just think: 4 players left means that this is the semi final.

Regards,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Switching from 2.3 to 2.6

2009-09-23 Thread Benno Lang
On Thu, Sep 24, 2009 at 5:46 AM, Kristina Ambert
 wrote:
> Hi guys,
> I'm getting this error after I tried to switch from python 2.3 to 2.6. I
> tried to look online for what it means, but I can't find any good
> explanation.
> Do any of you guys have any idea what's causing it and what it means?
> C:\Python26\lib\site-packages\win32\lib\dbi.py:13: DeprecationWarning: dbi
> module is obsolete, code should now use native python datetime and
> buffer/memoryview objects
>   DeprecationWarning)

Sounds like the dbi module has been deprecated: i.e. it's out of date,
and contains ugly code that will eventually be removed. Therefore, you
should change the parts of your code that use it. If you read the
error message, it tells you which up-to-date/better alternatives you
should be using instead.

n.b. this is general information; I have no knowledge of the specific
modules/objects listed.

HTH,
benno.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] small program

2009-10-02 Thread Benno Lang
On Thu, Oct 1, 2009 at 8:31 PM, Andrius  wrote:
> Hi!
>
> There are interesting online course
> http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-00Fall-2008/LectureVideos/index.htm
> where I'm trying to learn Python.
> Looks quite interesting and I would like to create a program which
> should repeat a simply string several times with list number before.
> Like "1. Wanna more. 2. Wanna more. ..."
> Suppose to a loop here repeating, say x times. Should it look like that:
>
> y="Wanna more. "
> x=1
> x=x+d:
> d=<100
> print d+y
>
> How to create a program for such kind of task?

[Forgot to reply-all the first time:]

Something like this should do the trick, if I get what you're trying to do:

x = 10
for i in range (1, x + 1):
   print i, "whee"

HTH,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Function design

2009-10-27 Thread Benno Lang
On Tue, Oct 27, 2009 at 8:21 AM, Dave Angel  wrote:
> I agree with Luke's comments.  But I'd like to point out an apparent bug (I
> haven't tried the code, this is just by inspection).
>
> You use the test
>     if '0' in row[.]
>
> that's not going to check for a zero value, it's going to check for a zero
> digit character somewhere in the value.  So 504 would also be recognized, as
> well as 540.

I thought this sounded rather fishy, along the following lines:
row is a list, so slicing it returns a list, so 'in' should compare
the list elements (i.e. the strings contained therein) with '0'; this
seems perfectly normal.

I have checked, and thankfully the world is not upside down. It would
only work the way you describe if row was a string, or if 'in' called
itself recursively when it found a list.

HTH,
benno
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] mod_python authentication

2009-12-05 Thread Benno Lang
On Sat, Dec 5, 2009 at 8:26 PM, Rayon  wrote:
> I need to  setup a login page for a web application but I am not finding any
> code in the mod_python doc that shows me how to do this.
>
> What is need is the code to tell apache to get this login data from a login
> page.

If you want Apache to directly handle logins via HTTP auth then you
don't need to write any code, just configure your vhost or .htaccess
file (see for example the AuthUserFile directive).

OTOH if you want to build your own login system (e.g. with user
details stored in a database) then you:
1) Make a regular HTML form with username and password fields
2) Write whatever login processing code you need, and have the form
submit to it.
3) Check for an active login session on every page that requires
authentication, and redirect them back to the login form if necessary.

HTH,
benno.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with a Dictionary

2010-01-07 Thread Benno Lang
On Thu, Jan 7, 2010 at 10:51 PM, Garry Bettle  wrote:
> I have a list that I output in the following order:
>
> 2010-01-07 1103 Sund A7 450m
> 2010-01-07  Sheff A7 500m
> 2010-01-07 1119 Sund A6 450m
> 2010-01-07 1128 Sheff A6 500m
> 2010-01-07 1134 Sund A5 450m
> 2010-01-07 1142 Sheff A7 500m
> 2010-01-07 1148 Sund A5 450m
> 2010-01-07 1157 Sheff A6 500m
> 2010-01-07 1204 Sund A4 450m
> 2010-01-07 1212 Sheff A5 500m
> 2010-01-07 1218 Sund A4 450m
> 2010-01-07 1227 Sheff A3 500m
> 2010-01-07 1232 Sund A4 450m
> 2010-01-07 1242 Sheff A4 500m
> 2010-01-07 1247 Sund A4 450m
> 2010-01-07 1258 Sheff A3 500m
> 2010-01-07 1304 Sund A3 450m
> 2010-01-07 1312 Sheff A4 500m
> 2010-01-07 1319 Sund HC 640m
> 2010-01-07 1327 Sheff A5 500m
> 2010-01-07 1333 Sund A3 450m
> 2010-01-07 1344 Sheff A3 500m
> 2010-01-07 1351 Sund A2 450m
> 2010-01-07 1403 Sheff A2 500m
> 2010-01-07 1408 Romfd A7 400m
> 2010-01-07 1418 Crayfd S8 540m
> 2010-01-07 1427 Romfd A6 400m
> 2010-01-07 1437 Crayfd H3 380m
> ... etc.
>
> The above are RaceDate + RaceTime + Fixture + RaceDetails, and are
> output in RaceTime order.
>
> What I'd like to do, is output a transposed-like summary of just the
> Fixture + RaceTime.
>
> i.e.
>
> Sund   1103 1119 1134 1148 1204 1218 1232 1247 1304 1319 1333 1351
> Sheff    1128 1142 1157 1212 1227 1242 1258 1312 1327 1344 1403
> Romfd 1408 1427 ...
> Crayfd 1418 1437 ...
>
> Do I need to use a Dictionary?

Not necessarily, but it would seem illogical not to do so.

HTH,
benno.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor