Re: [Tutor] mailing list

2008-09-16 Thread Evans
Hi, if it's Python tutorial you're after, then start from here 
http://docs.python.org/tut/ or do a search for 'Python tutorial' on any search 
engine.

Good luck!

--
Evans
  - Original Message - 
  From: Phite Marano 
  To: tutor@python.org 
  Sent: Tuesday, September 16, 2008 7:40 AM
  Subject: [Tutor] mailing list


  hi please send me all tutorials




--


  ___
  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] problem with building dict w/ SQlite SELECTS in loop

2008-09-16 Thread Tim Golden

Che M wrote:

(struggling to make an informative subject line)


[ struggling to understand exactly what the problem is... :) ]

I'm quite willing to help on this, but it's just not quite
clear enough what's happening. Can I suggest that you
post a *really small, self-contained* example which demonstrates
the problem you're having. You might actually realise what's
wrong as you do that, or if not someone like me can just run
the example and see what you mean and point things out.

Your code is missing just too many things for me
to work out which bit is doing what. (And it's a bit
awkward because of the long lines).

Try posting something like this:


import sqlite3

db = sqlite3.connect (":memory:")
db.execute ("CREATE TABLE codes (code)")
db.executemany ("INSERT INTO codes VALUES (?)", [(i,) for i in range (10)])

q = db.cursor ()
for n_try in range (3):
 q.execute ("SELECT * FROM codes WHERE code > ?", [n_try])
 q.fetchall ()

q.close ()




and say what you think should happen, and what does
happen. Note that the entire code I've posted there
can be dropped straight into an interpreter and run
which makes it much easier for people who are willing
to help to see what you're trying to do.

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


Re: [Tutor] mailing list

2008-09-16 Thread Alan Gauld

"Phite Marano" <[EMAIL PROTECTED]> wrote


hi please send me all tutorials


There are many Python tutorials on the web which you can find using
any search engine or the links on the Python web site. The one
that suits you bestwill depend on your own preferred style of 
learning.


The tutor mailing list is here to answer any specific questions you
might have while doing the tutorials.

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


[Tutor] WMI

2008-09-16 Thread Spencer Parker
Has anyone here had any experience with WMI extensions in Python?

I am trying to remotely change the IP, Subnet, and gateway of a windows
machine, but I cannot figure out what it needs to change this.

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


[Tutor] Creating a chat system Server

2008-09-16 Thread Richard Lovely
Does anyone have any links and or know of any good libraries for
writing chat servers similar to IRC?  I'm looking to add chat
facilities to a game I'm working on.

Thanks.
-- 
Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
www.theJNP.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Creating a chat system Server

2008-09-16 Thread W W
A lot of people referenced me to twisted whenever I asked about
sockets/threading.

HTH,
Wayne

On Tue, Sep 16, 2008 at 12:14 PM, Richard Lovely
<[EMAIL PROTECTED]>wrote:

> Does anyone have any links and or know of any good libraries for
> writing chat servers similar to IRC?  I'm looking to add chat
> facilities to a game I'm working on.
>
> Thanks.
> --
> Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
> www.theJNP.com
> ___
> 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] WMI

2008-09-16 Thread Tim Golden

Spencer Parker wrote:

Has anyone here had any experience with WMI extensions in Python?

I am trying to remotely change the IP, Subnet, and gateway of a windows 
machine, but I cannot figure out what it needs to change this. 


You'll need the Win32_NetworkAdapterConfiguration class and,
for ease, the wmi module from here:

http://timgolden.me.uk/python/wmi.html


import wmi

c = wmi.WMI ()

for i in c.Win32_NetworkAdapterConfiguration (IPEnabled=True):
  print i

You'll need things like the .SetGateways method. You can see
all the methods thus:

print "\n".join (i.methods)

and if you print any of them, it will show its signature:

print i.SetGateways




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


Re: [Tutor] WMI

2008-09-16 Thread Spencer Parker
This is the code that I currently have:

import wmi

con =wmi.WMI()
ip = "10.1.10.20"
subnet = "255.255.255.0"
gateway = "10.1.10.1"

wql = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled =
TRUE"

for adapter in con.query(wql):
ReturnValue = adapter.EnableStatic(IPAddress=ip, SubnetMask=subnet)

On Tue, Sep 16, 2008 at 1:01 PM, Tim Golden <[EMAIL PROTECTED]> wrote:

> Spencer Parker wrote:
>
>> Has anyone here had any experience with WMI extensions in Python?
>>
>> I am trying to remotely change the IP, Subnet, and gateway of a windows
>> machine, but I cannot figure out what it needs to change this.
>>
>
> You'll need the Win32_NetworkAdapterConfiguration class and,
> for ease, the wmi module from here:
>
> http://timgolden.me.uk/python/wmi.html
>
> 
> import wmi
>
> c = wmi.WMI ()
>
> for i in c.Win32_NetworkAdapterConfiguration (IPEnabled=True):
>  print i
>
> You'll need things like the .SetGateways method. You can see
> all the methods thus:
>
> print "\n".join (i.methods)
>
> and if you print any of them, it will show its signature:
>
> print i.SetGateways
>
> 
>
>
> HTH
> TJG
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



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


Re: [Tutor] WMI

2008-09-16 Thread Spencer Parker
It does of course help to spell IPAddress correctly to get this to work in
the first place.  LOL.  It is working...thanks again for the help and the
wonderful module!

On Tue, Sep 16, 2008 at 1:36 PM, Spencer Parker <[EMAIL PROTECTED]>wrote:

> This is the code that I currently have:
>
> import wmi
>
> con =wmi.WMI()
> ip = "10.1.10.20"
> subnet = "255.255.255.0"
> gateway = "10.1.10.1"
>
> wql = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled =
> TRUE"
>
> for adapter in con.query(wql):
> ReturnValue = adapter.EnableStatic(IPAddress=ip, SubnetMask=subnet)
>
>
> On Tue, Sep 16, 2008 at 1:01 PM, Tim Golden <[EMAIL PROTECTED]> wrote:
>
>> Spencer Parker wrote:
>>
>>> Has anyone here had any experience with WMI extensions in Python?
>>>
>>> I am trying to remotely change the IP, Subnet, and gateway of a windows
>>> machine, but I cannot figure out what it needs to change this.
>>>
>>
>> You'll need the Win32_NetworkAdapterConfiguration class and,
>> for ease, the wmi module from here:
>>
>> http://timgolden.me.uk/python/wmi.html
>>
>> 
>> import wmi
>>
>> c = wmi.WMI ()
>>
>> for i in c.Win32_NetworkAdapterConfiguration (IPEnabled=True):
>>  print i
>>
>> You'll need things like the .SetGateways method. You can see
>> all the methods thus:
>>
>> print "\n".join (i.methods)
>>
>> and if you print any of them, it will show its signature:
>>
>> print i.SetGateways
>>
>> 
>>
>>
>> HTH
>> TJG
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
> --
> Spencer Parker
>
>


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


Re: [Tutor] Creating a chat system Server

2008-09-16 Thread Winfried Tilanus
On 09/16/2008 W W wrote:

Hi,

> A lot of people referenced me to twisted whenever I asked about 
> sockets/threading.

You might want to use xmpp (the protocol of jabber). Twisted can speak
that, but there are other options. It is a quite versatile protocol:
beside 'just chatting', about anything that is real time over the net
can be done with it. A list of python-jabebr libraries can be found at:

http://www.jabber.org/web/Libraries#Python

Winfried

-- 
http://www.tilanus.com
xmpp:[EMAIL PROTECTED]
tel. 015-3613996 / 06-23303960
fax. 015-3614406
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem with building dict w/ SQlite SELECTS in loop

2008-09-16 Thread Che M


> I'm quite willing to help on this, but it's just not quite
> clear enough what's happening. Can I suggest that you
> post a *really small, self-contained* example which demonstrates
> the problem you're having. You might actually realise what's
> wrong as you do that, or if not someone like me can just run
> the example and see what you mean and point things out.

> Your code is missing just too many things for me
> to work out which bit is doing what. (And it's a bit
> awkward because of the long lines).
> 
> Try posting something like this:
> 
> 
> import sqlite3
> 
> db = sqlite3.connect (":memory:")
> db.execute ("CREATE TABLE codes (code)")
> db.executemany ("INSERT INTO codes VALUES (?)", [(i,) for i in range (10)])
> 
> q = db.cursor ()
> for n_try in range (3):
>   q.execute ("SELECT * FROM codes WHERE code > ?", [n_try])
>   q.fetchall ()
> 
> q.close ()
> 
> 
> > 
> and say what you think should happen, and what does
> happen. Note that the entire code I've posted there
> can be dropped straight into an interpreter and run
> which makes it much easier for people who are willing
> to help to see what you're trying to do.
> 
> TJG
> 

I normally do try to include a small runnable sample, but in this
case it seemed too extricated into the rest of my code.  As it happens,
as I was fooling around with variations of your code sample, it reinforced
my feeling that nothing was wrong with my loop and SQL query as such,
and it was then I noticed that it was the *list* that was wrong.

When I built my list, I built it using a .split() from a textbox field of 
comma-separated words.  But, I had written:

self.style_list = swlf.style_value.split(',')

when I should have written it as:

self.style_list = swlf.style_value.split(', ')


and that missing whitespace caused my list entries to each have
one whitespace in front of all but the very first item in the list, and
so of course they didn't match the words in the database.  So that
was the problem--I had been fixating on the SQL queries and it was
an improper use of .split() earlier in the code.  I have a feeling this
isn't the first time someone has made this mistake.

Thank you for your help,
Che


_
See how Windows connects the people, information, and fun that are part of your 
life.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093175mrt/direct/01/___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] WMI

2008-09-16 Thread Tim Golden

Spencer Parker wrote:
It does of course help to spell IPAddress correctly to get this to work 
in the first place.  LOL.  It is working...thanks again for the help and 
the wonderful module!



Glad it was useful. Thanks for the update.

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


Re: [Tutor] problem with building dict w/ SQlite SELECTS in loop

2008-09-16 Thread Tim Golden

Che M wrote:

[... snip solution around mis-handling a
string split ...]

Glad you solved it. Thanks for coming back with
an update. Depending on your circs, you might want
to try a more general solution to that problem, like:


s = "This,  is,a, string, with, varying,  amounts,   of,space"
print [s.strip () for s in s.split (",")]



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


Re: [Tutor] problem with building dict w/ SQlite SELECTS in loop

2008-09-16 Thread Tim Golden

Che M wrote:

[... snip solution around mis-handling a
string split ...]

Glad you solved it. Thanks for coming back with
an update. Depending on your circs, you might want
to try a more general solution to that problem, like:


s = "This,  is,a, string, with, varying,  amounts,   of,space"
print [s.strip () for s in s.split (",")]



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


Re: [Tutor] problem with building dict w/ SQlite SELECTS in loop

2008-09-16 Thread Che M

> I can't see any obvious reasons for your problems, I'm afraid, but I
> do have a comment on your SQL: the sqlite module supports using ? to
> indicate parameters.  So you could rewrite your select statements as:
> 
> cur.execute("select code from codes where code != '' and style = ? and
> start >= ? and start < ?", (style, self.start_datestring,
> self.end_datestring))
> 
> which is much easier to read, and also not vulnerable to SQL injection.

I will definitely adopt that (and had previously in other cases...for some
reason here I hadn't).  Thanks.

> Secondly, any reason why you aren't getting both code and start in a
> single select statement?  i.e.
> 
> cur.execute("select code, start from codes where code != '' and style
> = ? and start >= ? and start < ?", (style, self.start_datestring,
> self.end_datestring))

The reason is merely lack of experience and because of how I was
using the fetchall() in one list comprehension to build each list...since 
I did this twice, I thought I needed to restock the cursor, since each   
.fetchall() depletes the cursor.  But of course, that's dumb--now I 
just get fetchall() once first and do two list comprehensions, like:

fetched_data = cur.fetchall()
mycodes = [ str(row[0] for row in fetched_data ]
mystyles = [ str(row[1] for row in fetched_data ]

Much better--thank you.

> (heck, you could select code, start, style form codes -- pull all the
> information you need in a single query, and skip the loop
> altogether..)

I think I need the loop because the style will be multiple styles and
I need to take the codes that go with each style, so I am querying
style by style, so to speak.

Thanks,
Che

_
Stay up to date on your PC, the Web, and your mobile phone with Windows Live.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093185mrt/direct/01/___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem with building dict w/ SQlite SELECTS in loop

2008-09-16 Thread John Fouhy
2008/9/17 Che M <[EMAIL PROTECTED]>:
>> (heck, you could select code, start, style form codes -- pull all the
>> information you need in a single query, and skip the loop
>> altogether..)
> I think I need the loop because the style will be multiple styles and
> I need to take the codes that go with each style, so I am querying
> style by style, so to speak.

What I meant is that you could do this:

cur.execute("select code, start, style from codes where code != '' and
start > ? and start <= ?", #etc)
results = cur.fetchall()
self.style_data_dict = {}
for code, start, style in results:
  self.style_data_dict.setdefault(style, []).append((code, start))

This will leave your data dict in a different form from the one in
your original code.. but you could change it by:

for style in self.style_data_dict:
  self.style_data_dict[style] = zip(*self.style_data_dict[style])

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


Re: [Tutor] problem with building dict w/ SQlite SELECTS in loop

2008-09-16 Thread Alan Gauld

"Che M" <[EMAIL PROTECTED]> wrote


The reason is merely lack of experience and because of how I was
using the fetchall() in one list comprehension to build each list...


> (heck, you could select code, start, style form codes -- pull all 
> the

> information you need in a single query, and skip the loop


I think I need the loop because the style will be multiple styles 
and

I need to take the codes that go with each style, so I am querying
style by style, so to speak.


Check out the GROUP BY and ORDER BY clauses of a SELECT
statement. I'm pretty sure you could select all the stuff you want
using a combination of those two clauses. It should be much faster
and lead to more maintainable code too. Something like:

select code from codes where code != '' and style = ? and

start >= ? and start < ?


SELECT code, start
FROM codes
WHERE code != "" AND start >= begin AND start < end
GROUP BY style
ORDER BY style

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