[Tutor] Timer with exe command

2011-02-28 Thread Kaden McLaws



I would like to set up the following using python: A timer that is activated 
when a user logs on to our computer, then shuts the computer down when the 
timer runs out (no matter what, ending all programs). First, a raw input is 
used, so that if you know the password, you may shut off the timer (set for 90 
mins). Otherwise, it is activated. This is a timer to be used so (anonymous) 
can only spend 90 mins playing Modern Warfare, and not hours upon end like he 
does. I was also wondering about parsing. It would be effective if the last 
time the timer activated was recorded in a txt file, logged, so that the 
program can check and ensure that the last time the timer ended was at least 12 
hours ago, so the computer just isnt turned right back on for another 90 mins 
repeatedly.Is there also a way to run the python hidden in the background so he 
cannot just figure out how to close it?If you aren't sure off all the details, 
email me back. Thanks for helping me save (anonymous) from wasting too much 
time on MW2! :)


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


[Tutor] Bitwise operation

2011-02-28 Thread tee chwee liong

hi, 
 
i'm confused with & and AND. for eg:
>>> 1110 & 0110
64
>>> 1110 and 0110
72
 
i'm expecting if 1110 and with 0110 will get 0110 or 6. 
pls advise. 
 
thanks
tcl
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Bitwise operation

2011-02-28 Thread Martin A. Brown

 : i'm confused with & and AND. for eg:
 : >>> 1110 & 0110
 : 64
 : >>> 1110 and 0110
 : 72
 :  
 : i'm expecting if 1110 and with 0110 will get 0110 or 6. 
 : pls advise. 

Above, python thinks you are representing one number in decimal 
notation and the other in octal.

Decimal (no leading zeroes):
>>> 14 & 6
6

Binary (leading with '0b'):
>>> 0b1110 & 0b0110
6

Octal (leading with '0'):
>>> 016 & 006
6

Hexadecimal (leading with '0x'):
>>> 0xe & 0x06
6

Additionally, you will want to distinguish which operator you 
intend, bitwise or boolean.  It seems fairly clear that you are 
intending the bitwise operator if you are expecting '6' to be the 
answer.

  &   bitwise 'and'
  and boolean 'and'

Read these three sections, at least, to understand the 
operators you are trying to use:

  
http://docs.python.org/reference/expressions.html#unary-arithmetic-and-bitwise-operations
  http://docs.python.org/reference/expressions.html#boolean-operations
  http://docs.python.org/reference/expressions.html#summary

This may also be useful:

  
http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex

Good luck,

-Martin

-- 
Martin A. Brown
http://linux-ip.net/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Bitwise operation

2011-02-28 Thread David Hutto
On Mon, Feb 28, 2011 at 4:43 AM, Martin A. Brown  wrote:
>
>  : i'm confused with & and AND. for eg:
>  : >>> 1110 & 0110
>  : 64
>  : >>> 1110 and 0110
>  : 72
>  :
>  : i'm expecting if 1110 and with 0110 will get 0110 or 6.
>  : pls advise.
>
> Above, python thinks you are representing one number in decimal
> notation and the other in octal.
>
> Decimal (no leading zeroes):
 14 & 6
> 6
>
> Binary (leading with '0b'):
 0b1110 & 0b0110
> 6
>
> Octal (leading with '0'):
 016 & 006
> 6
>
> Hexadecimal (leading with '0x'):
 0xe & 0x06
> 6
>
> Additionally, you will want to distinguish which operator you
> intend, bitwise or boolean.  It seems fairly clear that you are
> intending the bitwise operator if you are expecting '6' to be the
> answer.
>
>  &       bitwise 'and'
>  and     boolean 'and'
>
> Read these three sections, at least, to understand the
> operators you are trying to use:
>
>  http://docs.python.org/reference/expressions.html#unary-arithmetic-and-bitwise-operations
>  http://docs.python.org/reference/expressions.html#boolean-operations
>  http://docs.python.org/reference/expressions.html#summary
>
> This may also be useful:
>
>  http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex
>
> Good luck,
And skill/memory/reference.

>
> -Martin
>
> --
> Martin A. Brown
> http://linux-ip.net/
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
According to theoretical physics, the division of spatial intervals as
the universe evolves gives rise to the fact that in another timeline,
your interdimensional counterpart received helpful advice from me...so
be eternally pleased for them.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Multiples python files

2011-02-28 Thread Christopher Brookes
Hi, first sorry for my poor english, i'm a french guy, i'm trying to make
the best :(

I would like to split my python script into multiples files.
I want :
A file which contains only class creations and methods,
A file with some personals functions
And a main.py which is the main script.

But i'm getting some problems
In class creation file, i've a init method which create a character  (it
works).
They are created in main.py like this :

herosAll = [
 Character(1,"Antaa","Soldat moins fort",15,5,8),
 Character(2,"Klaitos","Soldat moins fort",15,5,8)]

But when i want to display all information about my character with :

class Character():
def DisplayAll():
print ('There is', Character.CharacterCount, 'heros')
for heros in herosAll:
heros.DisplayCharacterInfos()

I'm getting :

Traceback (most recent call last):
  File "main.py", line 28, in 
Character.DisplayAll()
  File "/home/christopher/class_creation.py", line 53, in DisplayAll
for heros in herosAll:
NameError: global name 'herosAll' is not defined

I know the source of the problem. The list herosAll is declared in main.py
so he can't access to it. But i'm stuck here. How can he get it ?
Have I to append the list in the init method ?

Thank you for ready.



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


Re: [Tutor] Bitwise operation

2011-02-28 Thread tee chwee liong


> Binary (leading with '0b'):
> >>> 0b1110 & 0b0110
> 6
> 
> Good luck,
> 
> -Martin
> 

 
my IDLE seems to be giving me some funny error. i'm using Python 2.5 and Win 
XP. pls advise. 
 
>>> a=0b110010
SyntaxError: invalid syntax
>>> 0b1110 & 0b0110
SyntaxError: invalid syntax
>>> 0b10
SyntaxError: invalid syntax
>>> 
 
thanks
tcl   ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Multiples python files

2011-02-28 Thread Izz ad-Din Ruhulessin
Hi, you must pass the herosAll list to the DisplayAll() method like this

class Character():
@classmethod
def DisplayAll(herosAll):
print ('There is', Character.CharacterCount, 'heros')
for heros in herosAll:
heros.DisplayCharacterInfos()

herosAll = [
 Character(1,"Antaa","Soldat moins fort",15,5,8),
 Character(2,"Klaitos","Soldat moins fort",15,5,8)]

Character.DisplayAll(herosAll)


2011/2/28 Christopher Brookes 

> Hi, first sorry for my poor english, i'm a french guy, i'm trying to make
> the best :(
>
> I would like to split my python script into multiples files.
> I want :
> A file which contains only class creations and methods,
> A file with some personals functions
> And a main.py which is the main script.
>
> But i'm getting some problems
> In class creation file, i've a init method which create a character  (it
> works).
> They are created in main.py like this :
>
> herosAll = [
>  Character(1,"Antaa","Soldat moins fort",15,5,8),
>  Character(2,"Klaitos","Soldat moins fort",15,5,8)]
>
> But when i want to display all information about my character with :
>
> class Character():
> def DisplayAll():
> print ('There is', Character.CharacterCount, 'heros')
> for heros in herosAll:
> heros.DisplayCharacterInfos()
>
> I'm getting :
>
> Traceback (most recent call last):
>   File "main.py", line 28, in 
> Character.DisplayAll()
>   File "/home/christopher/class_creation.py", line 53, in DisplayAll
> for heros in herosAll:
> NameError: global name 'herosAll' is not defined
>
> I know the source of the problem. The list herosAll is declared in main.py
> so he can't access to it. But i'm stuck here. How can he get it ?
> Have I to append the list in the init method ?
>
> Thank you for ready.
>
>
>
> --
> Brookes Christopher.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Multiples python files

2011-02-28 Thread Izz ad-Din Ruhulessin
@classmethod
def DisplayAll(herosAll):

is of course:

@classmethod
def DisplayAll(cls, herosAll):

2011/2/28 Izz ad-Din Ruhulessin 

> Hi, you must pass the herosAll list to the DisplayAll() method like this
>
> class Character():
> @classmethod
> def DisplayAll(herosAll):
> print ('There is', Character.CharacterCount, 'heros')
> for heros in herosAll:
> heros.DisplayCharacterInfos()
>
> herosAll = [
>  Character(1,"Antaa","Soldat moins fort",15,5,8),
>  Character(2,"Klaitos","Soldat moins fort",15,5,8)]
>
> Character.DisplayAll(herosAll)
>
>
> 2011/2/28 Christopher Brookes 
>
>> Hi, first sorry for my poor english, i'm a french guy, i'm trying to make
>> the best :(
>>
>> I would like to split my python script into multiples files.
>> I want :
>> A file which contains only class creations and methods,
>> A file with some personals functions
>> And a main.py which is the main script.
>>
>> But i'm getting some problems
>> In class creation file, i've a init method which create a character  (it
>> works).
>> They are created in main.py like this :
>>
>> herosAll = [
>>  Character(1,"Antaa","Soldat moins fort",15,5,8),
>>  Character(2,"Klaitos","Soldat moins fort",15,5,8)]
>>
>> But when i want to display all information about my character with :
>>
>> class Character():
>> def DisplayAll():
>> print ('There is', Character.CharacterCount, 'heros')
>> for heros in herosAll:
>> heros.DisplayCharacterInfos()
>>
>> I'm getting :
>>
>> Traceback (most recent call last):
>>   File "main.py", line 28, in 
>> Character.DisplayAll()
>>   File "/home/christopher/class_creation.py", line 53, in DisplayAll
>> for heros in herosAll:
>> NameError: global name 'herosAll' is not defined
>>
>> I know the source of the problem. The list herosAll is declared in main.py
>> so he can't access to it. But i'm stuck here. How can he get it ?
>> Have I to append the list in the init method ?
>>
>> Thank you for ready.
>>
>>
>>
>> --
>> Brookes Christopher.
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Multiples python files

2011-02-28 Thread Christopher Brookes
I don't understand

@classmethod
def DisplayAll(cls, herosAll):

What is cls ?

2011/2/28 Izz ad-Din Ruhulessin 

> @classmethod
> def DisplayAll(herosAll):
>
> is of course:
>
> @classmethod
> def DisplayAll(cls, herosAll):
>
> 2011/2/28 Izz ad-Din Ruhulessin 
>
> Hi, you must pass the herosAll list to the DisplayAll() method like this
>>
>> class Character():
>> @classmethod
>> def DisplayAll(herosAll):
>>  print ('There is', Character.CharacterCount, 'heros')
>> for heros in herosAll:
>> heros.DisplayCharacterInfos()
>>
>> herosAll = [
>>  Character(1,"Antaa","Soldat moins fort",15,5,8),
>>  Character(2,"Klaitos","Soldat moins fort",15,5,8)]
>>
>> Character.DisplayAll(herosAll)
>>
>>
>> 2011/2/28 Christopher Brookes 
>>
>>>  Hi, first sorry for my poor english, i'm a french guy, i'm trying to
>>> make the best :(
>>>
>>> I would like to split my python script into multiples files.
>>> I want :
>>> A file which contains only class creations and methods,
>>> A file with some personals functions
>>> And a main.py which is the main script.
>>>
>>> But i'm getting some problems
>>> In class creation file, i've a init method which create a character  (it
>>> works).
>>> They are created in main.py like this :
>>>
>>> herosAll = [
>>>  Character(1,"Antaa","Soldat moins fort",15,5,8),
>>>  Character(2,"Klaitos","Soldat moins fort",15,5,8)]
>>>
>>> But when i want to display all information about my character with :
>>>
>>> class Character():
>>> def DisplayAll():
>>> print ('There is', Character.CharacterCount, 'heros')
>>> for heros in herosAll:
>>> heros.DisplayCharacterInfos()
>>>
>>> I'm getting :
>>>
>>> Traceback (most recent call last):
>>>   File "main.py", line 28, in 
>>> Character.DisplayAll()
>>>   File "/home/christopher/class_creation.py", line 53, in DisplayAll
>>> for heros in herosAll:
>>> NameError: global name 'herosAll' is not defined
>>>
>>> I know the source of the problem. The list herosAll is declared in
>>> main.py so he can't access to it. But i'm stuck here. How can he get it ?
>>> Have I to append the list in the init method ?
>>>
>>> Thank you for ready.
>>>
>>>
>>>
>>> --
>>> Brookes Christopher.
>>>
>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>
>


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


Re: [Tutor] Multiples python files

2011-02-28 Thread Izz ad-Din Ruhulessin
You can only call methods on a class without instantiating it, if it are
classmethods.

http://pyref.infogami.com/classmethod

2011/2/28 Christopher Brookes 

> I don't understand
>
> @classmethod
> def DisplayAll(cls, herosAll
> ):
>
> What is cls ?
>
> 2011/2/28 Izz ad-Din Ruhulessin 
>
>> @classmethod
>> def DisplayAll(herosAll):
>>
>> is of course:
>>
>> @classmethod
>> def DisplayAll(cls, herosAll):
>>
>> 2011/2/28 Izz ad-Din Ruhulessin 
>>
>> Hi, you must pass the herosAll list to the DisplayAll() method like this
>>>
>>> class Character():
>>> @classmethod
>>> def DisplayAll(herosAll):
>>>  print ('There is', Character.CharacterCount, 'heros')
>>> for heros in herosAll:
>>> heros.DisplayCharacterInfos()
>>>
>>> herosAll = [
>>>  Character(1,"Antaa","Soldat moins fort",15,5,8),
>>>  Character(2,"Klaitos","Soldat moins fort",15,5,8)]
>>>
>>> Character.DisplayAll(herosAll)
>>>
>>>
>>> 2011/2/28 Christopher Brookes 
>>>
  Hi, first sorry for my poor english, i'm a french guy, i'm trying to
 make the best :(

 I would like to split my python script into multiples files.
 I want :
 A file which contains only class creations and methods,
 A file with some personals functions
 And a main.py which is the main script.

 But i'm getting some problems
 In class creation file, i've a init method which create a character  (it
 works).
 They are created in main.py like this :

 herosAll = [
  Character(1,"Antaa","Soldat moins fort",15,5,8),
  Character(2,"Klaitos","Soldat moins fort",15,5,8)]

 But when i want to display all information about my character with :

 class Character():
 def DisplayAll():
 print ('There is', Character.CharacterCount, 'heros')
 for heros in herosAll:
 heros.DisplayCharacterInfos()

 I'm getting :

 Traceback (most recent call last):
   File "main.py", line 28, in 
 Character.DisplayAll()
   File "/home/christopher/class_creation.py", line 53, in DisplayAll
 for heros in herosAll:
 NameError: global name 'herosAll' is not defined

 I know the source of the problem. The list herosAll is declared in
 main.py so he can't access to it. But i'm stuck here. How can he get it ?
 Have I to append the list in the init method ?

 Thank you for ready.



 --
 Brookes Christopher.

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


>>>
>>
>
>
> --
> Brookes Christopher.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Timer with exe command

2011-02-28 Thread Wayne Werner
On Sun, Feb 27, 2011 at 9:02 PM, Kaden McLaws wrote:

>
>
> I would like to set up the following using python: A timer that is
> activated when a user logs on to our computer, then shuts the computer down
> when the timer runs out (no matter what, ending all programs). First, a raw
> input is used, so that if you know the password, you may shut off the timer
> (set for 90 mins). Otherwise, it is activated. This is a timer to be used so
> (anonymous) can only spend 90 mins playing Modern Warfare, and not hours
> upon end like he does.
> I was also wondering about parsing. It would be effective if the last time
> the timer activated was recorded in a txt file, logged, so that the program
> can check and ensure that the last time the timer ended was at least 12
> hours ago, so the computer just isnt turned right back on for another 90
> mins repeatedly.
> Is there also a way to run the python hidden in the background so he cannot
> just figure out how to close it?
> If you aren't sure off all the details, email me back. Thanks for helping
> me save (anonymous) from wasting too much time on MW2! :)
>

Well, most of this should be possible on a windows box, however it would
probably make more sense to get one of the net cafe softwares - unless
you're truly interested in learning.

Having made my own kiosk software for some internet terminals at work, I can
tell you that it's a fairly difficult process - and I was using Linux which
makes a lot of these things easier to do.

But if you get some of the software gaming cafes use it should have exactly
what you need - and unless you make about $0.25/hr, it will probably be
cheaper to spend $50-100 on one of those solutions.

Also, I'm very impressed that you thought out the requirements and possible
steps to accomplish your desires.

So, to summarize - spending the amount of time to make such a specific
software will probably not be worth your time - unless you're interested in
learning - so you could get a commercial solution. However, if you /are/
interested in learning, I'll recommend the win32api which should make
possible several of the things you want.

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


Re: [Tutor] Bitwise operation

2011-02-28 Thread Steven D'Aprano

tee chwee liong wrote:

my IDLE seems to be giving me some funny error. i'm using Python 2.5 and Win XP. pls advise. 
 

a=0b110010

SyntaxError: invalid syntax



Base two literals were only added to Python in version 2.6.

[steve@sylar ~]$ python2.6
...
>>> 0b111
7


In 2.5 and older, this is a syntax error:

[steve@sylar ~]$ python2.5
...
>>> 0b111
  File "", line 1
0b111
^
SyntaxError: invalid syntax



Either upgrade to 2.6, or learn to convert between binary and decimal or 
hexadecimal in your head:


>>> 0x07  # like binary 111
7


You can still convert from binary number *strings* in Python 2.5:

>>> int("111", 2)
7






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


Re: [Tutor] numpy import failure

2011-02-28 Thread Ezra Kahn

On 2/27/2011 9:36 PM, tutor-requ...@python.org wrote:

Date: Sun, 27 Feb 2011 18:58:46 -0800
From: Andre' Walker-Loud
To: Ezra Kahn
Cc:tutor@python.org
Subject: Re: [Tutor] numpy import failure
Message-ID:<75198436-f849-4994-8d48-1726c2ee7...@gmail.com>
Content-Type: text/plain; charset=us-ascii

Hi Ezra,

Are you using Mac OSX or LINUX or ...

If you have a preexisting python installation, it may be that when you launch 
python, it loads the older version, and not the new EPD version.  When you 
launch python, what do you see?  For example, on my Mac OSX, launched from 
Terminal, I get

% python
Enthought Python Distribution --http://www.enthought.com
Version: 6.2-2 (32-bit)

Python 2.6.5 |EPD 6.2-2 (32-bit)| (r265:79063, May 28 2010, 15:13:03)
[GCC 4.0.1 (Apple Inc. build 5488)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>  

whereas, if I use an older version, I get

% python
Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>  

You need to get the equivalent of the first option.  If you are definitely 
launching the Enthought python (from your new installation) and getting this 
error, then there is a problem with the package build on your machine.


Andre
Thanks again for your responses.  I am using MS Windows 7, and it turns 
out there was a problem with build and re-installing EPD fixed it.  I 
appreciate the help, I am so new at this, I don't know if things aren't 
working because it is me, or because something else is wrong (I feel 
like a person who has known how to drive for years, but never bothered 
to look under the hood of the car).  Anyway, thanks again.


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


Re: [Tutor] Converting .pyd to .so

2011-02-28 Thread j ram
> Wine is a good suggestion, but it takes up 3.53 MB. Is there a lighter
>> alternative?
>>
>
> So far, you didn't state whether the DLL actually uses Windows calls, but I
> would imagine it does, and if so, you can't use it on anything but Windows
> without emulating those calls, thus using Wine.
>
>
Sorry for not being more specific, the DLL actually uses Windows calls.



> If it's available in source form (C? C++? What else?), you can extract the
> part that's interesting to you and wrap that using Cython or ctypes (with
> Cython being substantially faster than SWIG or ctypes).
>
>
The Source is C. I've heard of Cython, would Cython be a more portable
alternative?


> However, you didn't give us any hints about what the DLL actually does, so
> we can't know if you really need to go that path or if you just failed to
> find the obvious portable alternative.
>
>
>
The DLL wraps a device driver, and the library of the SWIG wrapped device
driver calls is invoked from a Python app. I was trying to find how this
device driver (DLL) could be used on Linux without having to re-write the
whole driver code for Linux.

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


Re: [Tutor] numpy import failure

2011-02-28 Thread Andre' Walker-Loud
>> Andre
> Thanks again for your responses.  I am using MS Windows 7, and it turns out 
> there was a problem with build and re-installing EPD fixed it.  I appreciate 
> the help, I am so new at this, I don't know if things aren't working because 
> it is me, or because something else is wrong (I feel like a person who has 
> known how to drive for years, but never bothered to look under the hood of 
> the car).  Anyway, thanks again.

welcome to the club!


Andre


On Feb 28, 2011, at 7:34 AM, Ezra Kahn wrote:

> On 2/27/2011 9:36 PM, tutor-requ...@python.org wrote:
>> Date: Sun, 27 Feb 2011 18:58:46 -0800
>> From: Andre' Walker-Loud
>> To: Ezra Kahn
>> Cc:tutor@python.org
>> Subject: Re: [Tutor] numpy import failure
>> Message-ID:<75198436-f849-4994-8d48-1726c2ee7...@gmail.com>
>> Content-Type: text/plain; charset=us-ascii
>> 
>> Hi Ezra,
>> 
>> Are you using Mac OSX or LINUX or ...
>> 
>> If you have a preexisting python installation, it may be that when you 
>> launch python, it loads the older version, and not the new EPD version.  
>> When you launch python, what do you see?  For example, on my Mac OSX, 
>> launched from Terminal, I get
>> 
>> % python
>> Enthought Python Distribution --http://www.enthought.com
>> Version: 6.2-2 (32-bit)
>> 
>> Python 2.6.5 |EPD 6.2-2 (32-bit)| (r265:79063, May 28 2010, 15:13:03)
>> [GCC 4.0.1 (Apple Inc. build 5488)] on darwin
>> Type "help", "copyright", "credits" or "license" for more information.
> >>>  
>> whereas, if I use an older version, I get
>> 
>> % python
>> Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51)
>> [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
>> Type "help", "copyright", "credits" or "license" for more information.
> >>>  
>> You need to get the equivalent of the first option.  If you are definitely 
>> launching the Enthought python (from your new installation) and getting this 
>> error, then there is a problem with the package build on your machine.
>> 
>> 
>> Andre
> Thanks again for your responses.  I am using MS Windows 7, and it turns out 
> there was a problem with build and re-installing EPD fixed it.  I appreciate 
> the help, I am so new at this, I don't know if things aren't working because 
> it is me, or because something else is wrong (I feel like a person who has 
> known how to drive for years, but never bothered to look under the hood of 
> the car).  Anyway, thanks again.
> 
> Ezra
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] Converting .pyd to .so

2011-02-28 Thread Stefan Behnel

j ram, 28.02.2011 18:49:

Wine is a good suggestion, but it takes up 3.53 MB. Is there a lighter
alternative?


So far, you didn't state whether the DLL actually uses Windows calls, but I
would imagine it does, and if so, you can't use it on anything but Windows
without emulating those calls, thus using Wine.


Sorry for not being more specific, the DLL actually uses Windows calls.


If it's available in source form (C? C++? What else?), you can extract the
part that's interesting to you and wrap that using Cython or ctypes (with
Cython being substantially faster than SWIG or ctypes).


The Source is C. I've heard of Cython, would Cython be a more portable
alternative?


It's likely not more portable than SWIG.



However, you didn't give us any hints about what the DLL actually does, so
we can't know if you really need to go that path or if you just failed to
find the obvious portable alternative.


The DLL wraps a device driver, and the library of the SWIG wrapped device
driver calls is invoked from a Python app. I was trying to find how this
device driver (DLL) could be used on Linux without having to re-write the
whole driver code for Linux.


Again, you're not giving us enough information - what kind of device are 
you talking about?


Generally speaking, I doubt that a Windows device driver is of any use on a 
non-Windows operating system. There are exceptions such as NDISWrapper


http://en.wikipedia.org/wiki/NDISwrapper

but they are just that: exceptions. It's hard to emulate enough of the 
Windows driver support layer to make use of a Windows driver.


Anyway, this is no longer a Python problem, so this is getting off-topic 
for this list.


Stefan

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


Re: [Tutor] Multiples python files

2011-02-28 Thread Alan Gauld


"Christopher Brookes"  wrote


I don't understand

@classmethod
   def DisplayAll(cls, herosAll):

What is cls ?


This is one of the advanced techniques I referred to a few 
days ago.


Basically the "best"(?) solution to your problem is to store the 
list of characters inside the Character class as what is known 
as a class variable.


Then everytime you create a new Character you can  add it 
to the list by the init method. And when a character is deleted 
you remove it via the del method.


You can then define class methods to read/print the list, 
find out how many characters exist etc.


This is much cleaner than keeping a separate global variable 
since the code for managing characters is all in one place 
with the classs definition. But it does introduce a bunch of 
new syntax features which I didn't think you were ready for 
yet! :-)


One thing you will need to be very careful about as you go 
forward is namespaces. Remember that everytime you 
import a module you need to precede any names in that 
module with the module name. And names inside a class 
need to be preceded by the class name. And names inside 
objects need to be preceded by the object (variable) name.
If the class is inside a module you need to use both module 
and class. Thus if the Character class is defined inside 
character.py you would have something like this 
in main.py:


import character
myObj = character.Character()
print myObj.display()
print character.Character.displayAll()

etc.

You can simplify it by using the "from m import v" style:

from character import Character
myObj = Character()
myObj.display()
Character.displayAll()

etc.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


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


Re: [Tutor] Converting .pyd to .so

2011-02-28 Thread Alan Gauld

"j ram"  wrote

The DLL wraps a device driver, and the library of the SWIG wrapped 
device
driver calls is invoked from a Python app. I was trying to find how 
this
device driver (DLL) could be used on Linux without having to 
re-write the

whole driver code for Linux.


In general you can't use a device driver from one OS on another.
A device driver exposes a set of standard APIs that the OS
expects to find and use to make the device function. But the
way one OS (Windows) interacts with devices is very different
to the way another OS (Linux) will do it so the Windows API
will be completely useless to Linux.

Device drivers are amongst the least portable bits of software
you can create. They can be made portable across compilers
and even across dfferent OS from the same family - you can
often write one device driver for Linux/BSD/MacOS(Darwin)
because they are all flavours of Unix. But unless you are very
lucky a Windows device driver - even if you recompiled the
C code - would be completely useless on Linux.

But as Stefan says, this has now moved to the stage
where it has nothing to do with Python.

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


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


Re: [Tutor] Timer with exe command

2011-02-28 Thread Corey Richardson
On 02/27/2011 10:02 PM, Kaden McLaws wrote:
> I would like to set up the following using python: A timer that is activated 
> when a user logs on to our computer, then shuts the computer down when the 
> timer runs out (no matter what, ending all programs). First, a raw input is 
> used, so that if you know the password, you may shut off the timer (set for 
> 90 mins). Otherwise, it is activated. This is a timer to be used so 
> (anonymous) can only spend 90 mins playing Modern Warfare, and not hours upon 
> end like he does. I was also wondering about parsing. It would be effective 
> if the last time the timer activated was recorded in a txt file, logged, so 
> that the program can check and ensure that the last time the timer ended was 
> at least 12 hours ago, so the computer just isnt turned right back on for 
> another 90 mins repeatedly.Is there also a way to run the python hidden in 
> the background so he cannot just figure out how to close it?If you aren't 
> sure off all the details, email me back. Thanks for helping me save 
> (anonymous) from w
asting too much time on MW2! :)

http://docs.python.org/library/time.html#time.sleep
http://www.microsoft.com/windowsxp/using/helpandsupport/learnmore/ballew_commandline.mspx
(See "Shut Down the System")
http://docs.python.org/whatsnew/2.2.html?highlight=pyw (scroll down)
http://www.tutorial5.com/content/view/157/47/
http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files

Should be everything you need.

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


Re: [Tutor] numpy import failure

2011-02-28 Thread Alan Gauld


"Ezra Kahn"  wrote

appreciate the help, I am so new at this, I don't know if things 
aren't working because it is me, or because something else is wrong 
(I feel like a person who has known how to drive for years, but 
never bothered to look under the hood of the car).


Thats a good analogy and one that is true for many (most?) drivers 
today.
If they suddenly tried to service their own vehicle they would be 
lost.

(Nowadays, with the amount of electronics in there, even those of us
who have servivced an engine are a bit lost!! :-)

Its all a bit scary but eventually it starts making sense, just stick
with it :-)

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


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


Re: [Tutor] Timer with exe command

2011-02-28 Thread Corey Richardson
On 02/28/2011 03:30 PM, Corey Richardson wrote:
> On 02/27/2011 10:02 PM, Kaden McLaws wrote:
>> I would like to set up the following using python: A timer that is activated 
>> when a user logs on to our computer, then shuts the computer down when the 
>> timer runs out (no matter what, ending all programs). First, a raw input is 
>> used, so that if you know the password, you may shut off the timer (set for 
>> 90 mins). Otherwise, it is activated. This is a timer to be used so 
>> (anonymous) can only spend 90 mins playing Modern Warfare, and not hours 
>> upon end like he does. I was also wondering about parsing. It would be 
>> effective if the last time the timer activated was recorded in a txt file, 
>> logged, so that the program can check and ensure that the last time the 
>> timer ended was at least 12 hours ago, so the computer just isnt turned 
>> right back on for another 90 mins repeatedly.Is there also a way to run the 
>> python hidden in the background so he cannot just figure out how to close 
>> it?If you aren't sure off all the details, email me back. Thanks for helping 
>> me save (anonymous) from 
w
> asting too much time on MW2! :)
> 
> [...]
> 
> Should be everything you need.
> 

Oh, and

http://docs.python.org/library/subprocess.html

I partially disagree with Wayne, it is certainly doable, and isn't too
too hard, but it will certainly take some doing without any Python
knowledge, so do take the time to learn.

I suggest http://www.alan-g.me.uk/l2p/
-- 
Corey Richardson
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] string conversion

2011-02-28 Thread Robert Clement

Hi

I have a wxpython control in which users are intended to enter control 
characters used to define binary string delimiters,  eg. '\xBA\xBA' or 
'\t\r\n' .


The string returned by the control is a unicode version of the string 
entered by the user, eg.  u'\\xBA\\xBA'  or  u'\\t\\r\\n' .


I would like to be able retrieve the original string containing the 
escaped control characters or hex values so that I can assign it to a 
variable to be used to split the binary string.


Does anyone know of a way this can be achieved?

Thanks
Rob



--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

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


Re: [Tutor] string conversion

2011-02-28 Thread Steven D'Aprano

Robert Clement wrote:

Hi

I have a wxpython control in which users are intended to enter control 
characters used to define binary string delimiters,  eg. '\xBA\xBA' or 
'\t\r\n' .



Do you mean that your users enter *actual* control characters? What do 
they type to enter (say) an ASCII null character into the field?


Or do you mean they type the string representation of the control 
character, e.g. for ASCII null they press \ then 0 on their keyboard, 
and the field shows \0 rather than one of those funny little square 
boxes you get for missing characters in fonts.


I will assume you mean the second, because I can't imagine how to enter 
control characters directly into a field (other than the simple ones 
like newline and tab).



The string returned by the control is a unicode version of the string 
entered by the user, eg.  u'\\xBA\\xBA'  or  u'\\t\\r\\n' .


The data you are dealing with is binary, that is, made up of bytes 
between 0 and 255. The field is Unicode, that is, made up of characters 
with code points between 0 and some upper limit which is *much* higher 
than 255. If wxpython has some way to set the encoding of the field to 
ASCII, that will probably save you a lot of grief; otherwise, you'll 
need to decide what you want to do if the user types something like £ or 
© or other unicode characters.


In any case, it seems that you are expecting strings with the 
representation of control characters, rather than actual control characters.



I would like to be able retrieve the original string containing the 
escaped control characters or hex values so that I can assign it to a 
variable to be used to split the binary string.


You have the original string -- the user typed  , and 
you are provided  .


Remember that backslashes in Python are special, and so they are escaped 
when displaying the string. Because \t is used for the display of tab, 
it can't be used for the display of backslash-t. Instead the display of 
backslash is backslash-backslash. But that's just the *display*, not the 
string itself. If you type \t into your field, and retrieve the string 
which looks like u'\\t', if you call len() on the string you will get 2, 
not 3, or 6. If you print it with the print command, it will print as \t 
with no string delimiters u' and ' and no escaped backslash.


So you have the original string, exactly as typed by the user. I *think* 
what you want is to convert it to *actual* control characters, so that a 
literal backslash-t is converted to a tab character, etc.



>>> s = u'\\t'
>>> print len(s), s, repr(s)
2 \t u'\\t'
>>> t = s.decode('string_escape')
>>> print len(t), t, repr(t)
1   '\t'


Hope that helps.




--
Steven

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


[Tutor] Socket and Changing IP's

2011-02-28 Thread Jacob Bender

Tutors,

I was looking into network programming, and I came across a 
problem. Socket programs need an IP address to function correctly, 
right? Well, IP addresses are always changing, so how should I go about 
making sockets that will work for an extended period of time? Thanks in 
advance!

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


Re: [Tutor] Socket and Changing IP's

2011-02-28 Thread Wayne Werner
On Mon, Feb 28, 2011 at 5:49 PM, Jacob Bender wrote:

> Tutors,
>
>I was looking into network programming, and I came across a problem.
> Socket programs need an IP address to function correctly, right? Well, IP
> addresses are always changing, so how should I go about making sockets that
> will work for an extended period of time? Thanks in advance!


If your IP address is changing that frequently, something is probably wrong!

Your IP should basically stay the same from the time you connect to the
internet until the time you disconnect - longer if you use static IPs.

What are you attempting to program?

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


Re: [Tutor] Socket and Changing IP's

2011-02-28 Thread Jacob Bender

On 2/28/2011 6:57 PM, Wayne Werner wrote:
On Mon, Feb 28, 2011 at 5:49 PM, Jacob Bender > wrote:


Tutors,

   I was looking into network programming, and I came across a
problem. Socket programs need an IP address to function correctly,
right? Well, IP addresses are always changing, so how should I go
about making sockets that will work for an extended period of
time? Thanks in advance!


If your IP address is changing that frequently, something is probably 
wrong!


Your IP should basically stay the same from the time you connect to 
the internet until the time you disconnect - longer if you use static IPs.


What are you attempting to program?

-Wayne
I'm trying to be a host without having to keep the computer on ALL 
of the time. Acting as a "Dropbox" would be an example. My IP doesn't 
change very often. It's stayed the same for days.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Socket and Changing IP's

2011-02-28 Thread David Hutto
On Mon, Feb 28, 2011 at 7:02 PM, Jacob Bender  wrote:
> On 2/28/2011 6:57 PM, Wayne Werner wrote:
>
> On Mon, Feb 28, 2011 at 5:49 PM, Jacob Bender 
> wrote:
>>
>> Tutors,
>>
>>    I was looking into network programming, and I came across a problem.
>> Socket programs need an IP address to function correctly, right? Well, IP
>> addresses are always changing, so how should I go about making sockets that
>> will work for an extended period of time? Thanks in advance!
>
> If your IP address is changing that frequently, something is probably wrong!
> Your IP should basically stay the same from the time you connect to the
> internet until the time you disconnect - longer if you use static IPs.
> What are you attempting to program?
> -Wayne
>
>     I'm trying to be a host without having to keep the computer on ALL of
> the time.

If you don't want your computer on, and you want your hosting services
allocated elsewhere, then why are you worried about that particular
dynamically changing address?

Go static with "offsite".

 Acting as a "Dropbox" would be an example. My IP doesn't change
> very often. It's stayed the same for days.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>



-- 
According to theoretical physics, the division of spatial intervals as
the universe evolves gives rise to the fact that in another timeline,
your interdimensional counterpart received helpful advice from me...so
be eternally pleased for them.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Timer with exe command

2011-02-28 Thread Alan Gauld

"Kaden McLaws"  wrote


I would like to set up the following using python:
A timer that is activated when a user logs on to our computer,
then shuts the computer down when the timer runs out


You can do that from the Operating System, no programming
required. But hopw you do it wioll depend on which Operating
System you are running, which is about the only thing you
omit to mention!

Assuming it's Windows take a look at the 'at' command...
If its Linux or MacOS try 'cron'


parsing. It would be effective if the last time the timer activated
was recorded in a txt file, logged, so that the program can
check and ensure that the last time the timer ended was
at least 12 hours ago, so the computer just isnt turned
right back on for another 90 mins repeatedly.


That's a little bit more tricky but doable in a startup script.
Python might be a suitable medium for that task.


Is there also a way to run the python hidden in the
background so he cannot just figure out how to close it?


Not really. If he knows how to drive the OS well then pretty
much anything you do can be traced. You can of course
disguise the name of the script so it looks harmless, but
you can't hide the interpreter - unless you have a
separate copy with an obscure name...

HTH,

Alan G. 



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


[Tutor] A class that instantiates conditionally ?

2011-02-28 Thread David
I have an idea that might clean up my code slightly, if I can make one
of my classes
clever enough to refuse to instantiate itself if a necessary condition
is not met.

Below I propose some example code that seems to achieve this, and I am
asking here
for feedback on it, because I have not written much python. So I might be doing
something unwise due to fiddling with things I don't totally understand.

My aim is that instead of writing this:

class MyClass:
pass

condition = 0

if condition:
my_object = MyClass()
else:
my_object = None

I could instead write this:

class MyClass_2:
# put the if-test here inside the class

my_object_2 = MyClass_2(condition)

to achieve the goal that (my_object_2 == None) when (condition == False).

I read the (ver 2.6) Python Language Reference
 Section 3.4.1. Basic customization
 Section 3.4.3. Customizing class creation

Most of the content there is way beyond my current understanding, but I came up
with the following code, which seems to work:

class MyClass_2(object):
def __new__(self, condition):
if condition:
return object.__new__(self)
else:
return None

condition = 0
my_object_2 = MyClass_2(condition)
print my_object_2
condition = 1
my_object_2 = MyClass_2(condition)
print my_object_2

Can anyone see any technical or style issues with that? Or
alternatively reassure me that it is completely ok?
Thanks.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Socket and Changing IP's

2011-02-28 Thread Sander Sweers
On Tue,   1 Mar 2011, 01:02:23 CET, Jacob Bender  
wrote:
>           I'm trying to be a host without having to keep the computer on ALL 
> of the time. Acting as a "Dropbox" would be an example. My IP doesn't 
> change very often. It's stayed the same for days.

The best solution here is to get a hostname from a service like dyndns.org. It 
has easy ways to update the ip address off the hostname. Then from your script 
connect to the hostname instead of the ip directly.

Br
sander___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor