Re: What to use for finding as many syntax errors as possible.

2022-11-08 Thread Alex Hall
On Sunday, October 9, 2022 at 12:09:45 PM UTC+2, Antoon Pardon wrote:
> I would like a tool that tries to find as many syntax errors as possible 
> in a python file. I know there is the risk of false positives when a 
> tool tries to recover from a syntax error and proceeds but I would 
> prefer that over the current python strategy of quiting after the first 
> syntax error. I just want a tool for syntax errors. No style 
> enforcements. Any recommandations? -- Antoon Pardon

Bit late here, coming from the Pycoder's Weekly email newsletter, but I'm 
surprised that I don't see any mentions of 
[parso](https://parso.readthedocs.io/en/latest/):

> Parso is a Python parser that supports error recovery and round-trip parsing 
> for different Python versions (in multiple Python versions). Parso is also 
> able to list multiple syntax errors in your python file.

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


python on a thumb drive?

2010-03-05 Thread Alex Hall
Hello all,
My name is Alex. I am pretty new to Python, but I really like it.

I am trying to put my python and pythonw executables on my thumb
drive, along with packages, using Moveable Python, but I cannot figure
out how to run scripts using it. I would rather use a shell than the
script runner gui since it does not seem to work. Any suggestions?
Thanks!

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


imported var not being updated

2010-03-08 Thread Alex Hall
Hello all:
I have a project with many pyw files. One file holds a variable and a
function that I find myself using across many other pyw files, so I
called it helpers.pyw. The variable is "mostRecent", which is a string
and is meant to hold a string so I know what the program most recently
output; in all the other pyw files, every time the program outputs
something, I include the line
helpers.mostRecent=output
where output is a string and helpers has been imported.

The problem is that mostRecent does not seem to be updated at all, and
I cannot figure out why. I declare it with empty quotes initially, but
the program should keep updating it. Everytime I go to see what its
value is, though, it is still apparently empty. Here is a basic
sample:

randomFile.pyw
---
import helpers

def something():
  output="I am the most recently output string!"
  helpers.mostRecent=output
#end def

file2.pyw
---
from helpers import mostRecent

print(mostRecent) #prints nothing

Any thoughts on what I am doing wrong? Thanks!!

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: imported var not being updated

2010-03-08 Thread Alex Hall
Thanks, it worked as expected. I guess I figured that Python would
read my mind and realize that I wanted mostRecent to act globally for
the program, imported as a copy or accessed in its own namespace
(right term?) Oh well, the day computers can read thoughts like that
is the day programmers are out of a job... Thanks again.

On 3/8/10, Gary Herron  wrote:
> Alex Hall wrote:
>> Hello all:
>> I have a project with many pyw files. One file holds a variable and a
>> function that I find myself using across many other pyw files, so I
>> called it helpers.pyw. The variable is "mostRecent", which is a string
>> and is meant to hold a string so I know what the program most recently
>> output; in all the other pyw files, every time the program outputs
>> something, I include the line
>> helpers.mostRecent=output
>> where output is a string and helpers has been imported.
>>
>> The problem is that mostRecent does not seem to be updated at all, and
>> I cannot figure out why. I declare it with empty quotes initially, but
>> the program should keep updating it. Everytime I go to see what its
>> value is, though, it is still apparently empty. Here is a basic
>> sample:
>>
>> randomFile.pyw
>> ---
>> import helpers
>>
>> def something():
>>   output="I am the most recently output string!"
>>   helpers.mostRecent=output
>> #end def
>>
>> file2.pyw
>> ---
>> from helpers import mostRecent
>>
>> print(mostRecent) #prints nothing
>>
>> Any thoughts on what I am doing wrong? Thanks!!
>>
>
> The form of import you are using
> from helpers import mostRecent
> makes a *new* binding to the value in the module that's doing the
> import.  Rebinding the var in a different module does not affect this.
> It's similar to this:
>
> a = 'string'
> b = a
> a = 'another string'
>
> won't affect b's value.
>
> What you can do, is not make a separate binding, but reach into the
> helpers module to get the value there.  Like this:
>
> import helpers
> print helpers.mostRecent
>
> That will work as you hope.
>
> Gary Herron
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


odd error

2010-03-09 Thread Alex Hall
Hi all,
In the same program I wrote about yesterday, I have a dictionary of
keystrokes which are captured. I just tried adding a new one, bringing
the total to 11. Here are entries 10 and 11; 10 has been working fine
for months.

  10 : (57, win32con.MOD_CONTROL),
  11 : (99, win32con.MOD_CONTROL | win32con.MOD_SHIFT)

Now, though, when I press ctrl-shift-c (keystroke 11), nothing
happens. Pressing any other keystroke after that will crash the
program with some sort of Python internal com server exception that I
have never seen before. When set to a keystroke I already use, such as
#10, the function called by #11 works just fine. Does anyone see a
problem with the above syntax? The trouble almost definitely has to be
there; again, using an already-working keystroke instead of making a
new one works perfectly, it is just when I add this new one that
things break.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: odd error

2010-03-09 Thread Alex Hall
I know ctrl-c kills a process in the shell, but these are global
hotkeys and all others work fine. You made me discover something,
though: the error only happens if ctrl-shift-c is pressed when in the
shell from where the program was run; when pressed anywhere else, the
keystroke does nothing at all. Is there something I am missing about
these keystroke dictionaries? It seems like they do not work unless
the keycodes are in numerical order and are not separated by more than
one number. Currently, my dictionary consists of the numbers 1-0 on
the top of the keyboard, but adding any other keycode, like the 99 in
my original message, will cause that keystroke to do absolutely
nothing. Thanks to your response, I suspect the problem is something
to do with the keypress being captured by the shell. Still, not being
able to use anything except numbers is very annoying!! Why would this
be happening?


On 3/9/10, Ulrich Eckhardt  wrote:
> Alex Hall wrote:
>> Now, though, when I press ctrl-shift-c (keystroke 11), nothing
>> happens.
>
> Control-C sends a special signal to the console, like Control-Break.
>
>> Pressing any other keystroke after that will crash the program
>> with some sort of Python internal com server exception that I
>> have never seen before.
>
> Neither do I, in particular since you don't share that rare gem with us. ;)
>
> Uli
>
> --
> Sator Laser GmbH
> Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: odd error

2010-03-09 Thread Alex Hall
Okay, I changed the keycode from 99 (c) to 107 (k), and the errors
have disappeared. However, now the function that should be called is
not. As I said in a previous message, I have always had trouble with
this sort of keystroke dictionary. It seems like, if a keycode is out
of order or not one more than the number before it, the function to
which it is tied will not get called. I am using the message looping
mode from Tim Golden's website, and it works beautifully until I try
to put an out-of-sequence keycode into the keystrokes dictionary. The
dictionary contains numbers 0-9 (48-57) and all is well, but when I
put in this 107 code then the function tied to 107 is not called, yet
the ones tied to 48-57 still work normally. Why would the sequence
matter, or does it not and I am doing something else wrong? Here is a
sample of my dictionary:

keys.append({
  1 : (48, win32con.MOD_CONTROL),
  2 : (49, win32con.MOD_CONTROL),
  3 : (50, win32con.MOD_CONTROL),
  4 : (51, win32con.MOD_CONTROL),
  5 : (52, win32con.MOD_CONTROL),
  6 : (53, win32con.MOD_CONTROL),
  7 : (54, win32con.MOD_CONTROL),
  8 : (55, win32con.MOD_CONTROL),
  9 : (56, win32con.MOD_CONTROL),
  10 : (57, win32con.MOD_CONTROL),
  11 : (107, win32con.MOD_CONTROL | win32con.MOD_SHIFT) #never calls
its #function, and note that it is not in the sequence of the other
ten
})

and here is a list of functions tied to it:

funcs.append({
  1 : exitProgram,
  2 : arm.sayLoad1,
  3 : arm.sayLoad2,
  4 : arm.sayLoad3,
  5 : arm.sayLoad4,
  6 : arm.sayProcAvg,
  7 : arm.sayUsedRam,
  8 : arm.sayDisk1Info,
  9 : arm.sayDisk2Info,
  10 : nextMode,
  11: clipboard.toClipboard
})

If I were to tie clipboard.toClipboard to any of keys 1-10 (0-9, or
48-57) then it would work fine; it is when the 107 shows up that the
function is not called, and this is a huge limitation for the rest of
the program since I am stuck with just the ten numbers available on
the keyboard. Any suggestions would be great!


On 3/9/10, Tim Golden  wrote:
> On 09/03/2010 13:55, Alex Hall wrote:
>> Hi all,
>> In the same program I wrote about yesterday, I have a dictionary of
>> keystrokes which are captured. I just tried adding a new one, bringing
>> the total to 11. Here are entries 10 and 11; 10 has been working fine
>> for months.
>>
>>10 : (57, win32con.MOD_CONTROL),
>>11 : (99, win32con.MOD_CONTROL | win32con.MOD_SHIFT)
>>
>> Now, though, when I press ctrl-shift-c (keystroke 11)
>
> Ctrl-C (with or without any other modifier) has a special meaning
> which overrides any hotkeys. You may be able to do something by
> adding a break handler through SetConsoleCtrlHandler (exposed in
> win32api). But it would obviously be a special case outside your
> normal control flow.
>
> TJG
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: odd error

2010-03-10 Thread Alex Hall
I am honestly a bit lost as to why keys.append() is not a good choice
here, but I have it working. I apparently have to use the ascii for
capital letters if I am capturing the shift modifier, not the
lowercase ascii. Using 67 instead of 99 works as expected.

I use append because the program has three different modes.
Eventually, each mode may have its own keystrokes. When the user
switches modes, the previous mode's keystrokes are unregistered and
the new keystrokes, keys[currentModeNumber], are registered. The same
with the functions; when a function is called from the dictionary, it
is called using funcs[currentModeNumber]. Again, this lets me put all
my functions into one big list, where each member of the list is a
dictionary. I probably have the terminology wrong, but hopefully that
makes sense. Sorry for not explaining that earlier, but I was just
looking for problems in the key codes. Thanks for your help!

On 3/10/10, Tim Golden  wrote:
> On 10/03/2010 09:16, Steven D'Aprano wrote:
>> Perhaps all you need is a single dict, mapping characters to functions:
>>
>> funcs = {  # Just a dict
>>  # keycode: function
>>  'q': exitProgram,
>>  'a': arm.sayLoad1
>>  # etc.
>>  }
>>
>>
>> Then whenever you get a keyboard event, convert it to the character:
>>
>> keycode = 113
>> c = chr(keycode)
>> funcs(c)()
>
> FWIW (altho' it's not clear from the OP's code) he's basically
> doing this:
>
> http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkeys.html
>
> which uses the dictionary keys as an id in the call to RegisterHotKey.
>
> Obviously, that doesn't explain why he's building lists of dictionaries.
>
>
> TJG
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


importing modules from subdirs

2010-03-11 Thread Alex Hall
Hi all,
The manual says, for modules in a project stored in subdirectories, you can do:
import folderName.module

I have a couple questions, though:
1. Do I then have to call functions from module like
folder.module.function, or can I still use the normal module.function?

2. When I try to do this, it fails. I have an sw folder. Inside that I
have a modes folder, holding weather.pyw. Main.pyw, back in the sw
folder, is trying to import modes.weather, but nothing happens. I have
tried putting weather.pyw in its own weather folder under the modes
folder, but that also fails. I have placed an empty __init__.py file
in both the modes folder and the weather subfolder, but I cannot get
main.pyw to import weather!

3. How does weather import from a folder above or beside it? For
example, if a config directory is at the same level as the modes
directory, how can weather import something from config?

Thanks!

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


unable to run wxPython script: dll errors

2010-03-11 Thread Alex Hall
Hi all,
I am trying to run a file that should pop up a dialog. The dialog is
fine (I used XRCed to create it and running it from within that editor
brings up the dialog I want). When I run my file, though, I get this
traceback:

C:\Users\Alex>c:\python26\python.exe i:\arm\dictionary.py
Traceback (most recent call last):
  File "i:\arm\dictionary.py", line 2, in 
import wx
  File "c:\python26\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py", line 4
5, in 
from wx._core import *
  File "c:\python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 4, i
n 
import _core_
ImportError: DLL load failed: The specified procedure could not be found.

I am running win7x64, wxPython2.8, python2.6. Any ideas why this would
be happening? I found a forum post that talked about a manifest file
and some dll files being needed, but it did not make a lot of sense.
Thanks!


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: importing modules from subdirs

2010-03-11 Thread Alex Hall
Halfway there. It imports now, but it says that the module does not
have functions which I know it does have. I will just leave it all in
one folder for now and play with organization after I get the project
working better.

On 3/11/10, Steve Holden  wrote:
> Alex Hall wrote:
>> Hi all,
>> The manual says, for modules in a project stored in subdirectories, you
>> can do:
>> import folderName.module
>>
>> I have a couple questions, though:
>> 1. Do I then have to call functions from module like
>> folder.module.function, or can I still use the normal module.function?
>>
>> 2. When I try to do this, it fails. I have an sw folder. Inside that I
>> have a modes folder, holding weather.pyw. Main.pyw, back in the sw
>> folder, is trying to import modes.weather, but nothing happens. I have
>> tried putting weather.pyw in its own weather folder under the modes
>> folder, but that also fails. I have placed an empty __init__.py file
>> in both the modes folder and the weather subfolder, but I cannot get
>> main.pyw to import weather!
>>
>> 3. How does weather import from a folder above or beside it? For
>> example, if a config directory is at the same level as the modes
>> directory, how can weather import something from config?
>>
>> Thanks!
>>
> I haven't checked this, but I believe .pyw names are only for main
> programs. Try renaming weather.pyw as weather.py and see if it makes any
> difference.
>
> regards
>  Steve
> --
> Steve Holden   +1 571 484 6266   +1 800 494 3119
> See PyCon Talks from Atlanta 2010  http://pycon.blip.tv/
> Holden Web LLC http://www.holdenweb.com/
> UPCOMING EVENTS:http://holdenweb.eventbrite.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


wx error, I suspect my class

2010-03-13 Thread Alex Hall
Hello all,
I am trying to make a gui out of xrc and wxpython, but I think my
understanding of Python's class/method structure is causing problems.
The below code returns an error on the line
  panel=xrc.XRCCTRL(mf, "dl")
The error goes back to wxPython itself and says "attribute error:
'none' type object has no attribute 'FindWindowById'"
Here is my complete code:

import wx
from wx import xrc

class myapp(wx.App):
 def OnInit(self):
  #load the xrc file
  res=xrc.XmlResource('dictionary.xrc')

  #load the frame containing everything else
  mf=res.LoadFrame(None, "mainframe")

  #assign all necessary controls to variables (text boxes and buttons)
for easier binding
  #format: varName=xrc.XRCCTRL(parent, IDFromXRCFile)
  panel=xrc.XRCCTRL(mf, "dl")
  btn_go=xrc.XRCCTRL(panel, "btn_go")
  btn_close=xrc.XRCCTRL(panel, "btn_close")

  #now bind the gui controls to functions
  mf.Bind(wx.EVT_BUTTON, close, id=xrc.XRCID("btn_close"))
  mf.Show()
 #end def OnInit

 def close(self):
  mf.Close(True)
 #end def close
#end class myapp

win=myapp(False)
win.MainLoop()

That is all there is to it. I made the xrc file with XRCed, so I know
it is properly formatted. I always see Python methods and classes
using the "self" keyword, but I never understood why or when to/not to
use it. I probably need it in the above code, but I am not sure how to
insert it correctly. I have been fighting with this code for the last
two days with no progress, so I would greatly appreciate any help you
can provide. Thanks.


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


problem with variable and function

2010-03-14 Thread Alex Hall
Hi all,
I have a file with a dictionary and a function. The dictionary holds
the name of the function, and the function references the dictionary.
If I put the dictionary first, the function is happy but the
dictionary says the function is not defined. If I switch the two and
put the function first, the function says the dictionary does not
exist. Does anyone have an idea as to how I can make both of them
happy? Thanks!

Example:

myVar={
 1:myFunc
}

def myFunc():
 myOtherVar=myVar

would result in myVar saying myFunc does not exist. Reverse it, though:

def myFunc():
 myOtherVar=myVar

myVar={
 1:myFunc
}

and the function myFunc does not see the dictionary. I basically
cannot win either way, and I need a way to resolve this. If you are
curious, the dictionary holds function names and maps to a second
dictionary of keystrokes, allowing me to map a keystroke to call a
function. Thanks!

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with variable and function

2010-03-14 Thread Alex Hall
Below is pasted the function which is looking for the "funcs"
dictionary, as well as the dictionary. They appear in my py file in
this order, yet I get an error in nextMode() that "global name 'funcs'
is not defined". Oddly, the keys dictionary works fine; it is defined
above the nextMode function.

def nextMode():
 global HOTKEYS
 global HOTKEY_ACTIONS
 global mode
 global modes
 global modeNum
 global modeNames
 global funcs
 #mode=mode+1
 #check to make sure the newly selected mode is enabled
 tmp=0
 while(tmp wrote:
> On Sun, Mar 14, 2010 at 10:26 AM, Alex Hall  wrote:
>> Hi all,
>> I have a file with a dictionary and a function. The dictionary holds
>> the name of the function, and the function references the dictionary.
>> If I put the dictionary first, the function is happy but the
>> dictionary says the function is not defined. If I switch the two and
>> put the function first, the function says the dictionary does not
>> exist. Does anyone have an idea as to how I can make both of them
>> happy?
> 
>> Reverse it, though:
>>
>> def myFunc():
>>  myOtherVar=myVar
>>
>> myVar={
>>  1:myFunc
>> }
>>
>> and the function myFunc does not see the dictionary.
>
> Please be more specific in what you mean by it not "seeing" the
> dictionary, because the "reversed" approach *should* work:
>
> $ python
> Python 2.6.4 (r264:75706, Feb 25 2010, 01:21:39)
> [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>>>> def foo():
> ... bar = baz
> ... print bar
> ...
>>>> baz = {1:foo}
>>>> foo()
> {1: }
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with variable and function

2010-03-14 Thread Alex Hall
>> #we now have the default mode to be used, but what if it is disabled?
>> if(sys.modules[modeNames[mode]].enabled=='False'):
>>  nextMode()
>
>How is this call supposed to work when `funcs` (which nextMode() uses)
>hasn't been defined yet?!

That seems to have done it, thanks. Sorry about top-posting; inline
posting is much harder to read when using a screen reader, as I do, so
I am used to top-posting.


On 3/14/10, Chris Rebert  wrote:
>> On 3/14/10, Chris Rebert  wrote:
>>> On Sun, Mar 14, 2010 at 10:26 AM, Alex Hall  wrote:
>>>> Hi all,
>>>> I have a file with a dictionary and a function. The dictionary holds
>>>> the name of the function, and the function references the dictionary.
>>>> If I put the dictionary first, the function is happy but the
>>>> dictionary says the function is not defined. If I switch the two and
>>>> put the function first, the function says the dictionary does not
>>>> exist. Does anyone have an idea as to how I can make both of them
>>>> happy?
>>> 
>>>> Reverse it, though:
>>>>
>>>> def myFunc():
>>>>  myOtherVar=myVar
>>>>
>>>> myVar={
>>>>  1:myFunc
>>>> }
>>>>
>>>> and the function myFunc does not see the dictionary.
>>>
>>> Please be more specific in what you mean by it not "seeing" the
>>> dictionary, because the "reversed" approach *should* work:
>>>
>>> $ python
>>> Python 2.6.4 (r264:75706, Feb 25 2010, 01:21:39)
>>> [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
>>> Type "help", "copyright", "credits" or "license" for more information.
>>>>>> def foo():
>>> ... bar = baz
>>> ... print bar
>>> ...
>>>>>> baz = {1:foo}
>>>>>> foo()
>>> {1: }
>
> On Sun, Mar 14, 2010 at 11:12 AM, Alex Hall  wrote:
>> Below is pasted the function which is looking for the "funcs"
>> dictionary, as well as the dictionary. They appear in my py file in
>> this order, yet I get an error in nextMode() that "global name 'funcs'
>> is not defined". Oddly, the keys dictionary works fine; it is defined
>> above the nextMode function.
>
> Please include the full exception Traceback.
> Also, please don't top-post in the future.
>
>> def nextMode():
>>  global HOTKEYS
>>  global HOTKEY_ACTIONS
>>  global mode
>
> You don't need a `global` declaration unless your function needs to
> rebind the global variable in question.
> So you can remove the next 4 global declarations; they're unnecessary.
>
>>  global modes
>>  global modeNum
>>  global modeNames
>>  global funcs
>>  #mode=mode+1
>>  #check to make sure the newly selected mode is enabled
>>  tmp=0
>>  while(tmp>  mode=(mode+1)%modeNum
>>  if(sys.modules[modeNames[mode]].enabled=='True'):
>>   break #break on the first enabled mode we find
>>  #end if
>>  tmp+=1
>>  #end while
>>  HOTKEYS=keys[mode]
>>  HOTKEY_ACTIONS=funcs[mode]
>>  registerHotkeys()
>>  speak("Now in "+str(modes[mode])+" mode.")
>> #end def
>>
>> #we now have the default mode to be used, but what if it is disabled?
>> if(sys.modules[modeNames[mode]].enabled=='False'):
>>  nextMode()
>
> How is this call supposed to work when `funcs` (which nextMode() uses)
> hasn't been defined yet?!
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


dll in project?

2010-03-14 Thread Alex Hall
Hi all,
I have a dll I am trying to use, but I get a Windows error 126, "the
specified module could not be found". Here is the code segment:
nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll")  

I have the specified dll file in the same directory as the file trying
to use said dll, and this is the only reference I make to the dll. Do
I need to register it somehow? If so, does this need to be done once,
or each time the application runs? If I need to register it, how would
I do so? Thanks!
-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dll in project?

2010-03-15 Thread Alex Hall
On 3/15/10, Ulrich Eckhardt  wrote:
> Alex Hall wrote:
>> I have a dll I am trying to use, but I get a Windows error 126, "the
>> specified module could not be found". Here is the code segment:
>> nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll")
>
> In addition to Alf's answer, this can also happen when the OS can't find
> another DLL that this one depends on.

Well, os.getcwd() returns "c:\python26", not my program's directory.
However, I changed the reference to the dll to be
helpers.progdir+'\\nvdaControllerClient32.dll'
and still no luck! helpers.progdir is a var holding the top-level
directory of my project, using os.path. Again, using this more precise
reference still fails, triggering my except statement in my try/catch
loop.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dll in project?

2010-03-15 Thread Alex Hall
Okay, I got a new copy and all seems well now. The dll is found and
loaded. The functions inside the dll are not working, but that is not
Python's fault. Thanks to everyone for your help and suggestions!

On 3/15/10, Ulrich Eckhardt  wrote:
> Alex Hall wrote:
>> On 3/15/10, Ulrich Eckhardt  wrote:
>>> Alex Hall wrote:
>>>> I have a dll I am trying to use, but I get a Windows error 126, "the
>>>> specified module could not be found". Here is the code segment:
>>>> nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll")
>>>
>>> In addition to Alf's answer, this can also happen when the OS can't find
>>> another DLL that this one depends on.
>
> Did you check if this could be the case?
>
>> Well, os.getcwd() returns "c:\python26", not my program's directory.
>> However, I changed the reference to the dll to be
>> helpers.progdir+'\\nvdaControllerClient32.dll'
>> and still no luck!
>
> Generally, there is os.path.join() IIRC which does this portably. This
> probably doesn't matter though. What I would check is firstly if this file
> could be opened at all, e.g. using os.stat().
>
>> helpers.progdir is a var holding the top-level directory of my
>> project, using os.path.
>
> Huh? In what way using os.path?
>
>> Again, using this more precise reference still fails, triggering my
>> except statement in my try/catch loop.
>
> Same error? See my initial guess! As a tool for finding out if there are
> missing dependencies, take a look at http://dependencywalker.com
>
> BTW: No need to CC me, I read your initial request here, I can ready any
> follow-ups here, too. ;)
>
> Uli
>
> --
> Sator Laser GmbH
> Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


using message loop for hotkey capturing

2010-03-23 Thread Alex Hall
Hi all, but mainly Tim Golden:
Tim, I am using your wonderful message loop for keyboard input, the
one on your site that you pointed me to a few months ago. It has been
working perfectly as long as I had only one dictionary of keys mapping
to one dictionary of functions, but now I want two of each. My program
has different modes, which may have varying keystrokes, and I also
have some global keystrokes which are the same across all modes, like
exiting or switching modes. I cannot figure out how to make the
message loop look in two dictionaries at onc. I tried using an if,
saying that if action_to_take was not set in the mode-specific
dictionary then look at the global dictionary, but it is like it is
never looking in the global dictionary at all. I get no syntax errors
or problems when running the program, so it has to be something in my
logic. Go to
http://www.gateway2somewhere.com/sw/main.pyw
to see what I mean; the problem code is near the very bottom of the
file. Thanks for any suggestions. Oh, please note that I indent one
space per indentation level.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using message loop for hotkey capturing

2010-03-23 Thread Alex Hall
Sorry about that, it is fixed now.

On 3/23/10, Tim Golden  wrote:
> On 23/03/2010 17:01, Alex Hall wrote:
>> Hi all, but mainly Tim Golden:
>> Tim, I am using your wonderful message loop for keyboard input, the
>> one on your site that you pointed me to a few months ago. It has been
>> working perfectly as long as I had only one dictionary of keys mapping
>> to one dictionary of functions, but now I want two of each. My program
>> has different modes, which may have varying keystrokes, and I also
>> have some global keystrokes which are the same across all modes, like
>> exiting or switching modes. I cannot figure out how to make the
>> message loop look in two dictionaries at onc. I tried using an if,
>> saying that if action_to_take was not set in the mode-specific
>> dictionary then look at the global dictionary, but it is like it is
>> never looking in the global dictionary at all. I get no syntax errors
>> or problems when running the program, so it has to be something in my
>> logic. Go to
>> http://www.gateway2somewhere.com/sw/main.pyw
>
>
> Happy to look, Alex, but that link's giving me a 404 at the moment
>
> TJG
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using message loop for hotkey capturing

2010-03-23 Thread Alex Hall
On 3/23/10, MRAB  wrote:
> Alex Hall wrote:
>> Hi all, but mainly Tim Golden:
>> Tim, I am using your wonderful message loop for keyboard input, the
>> one on your site that you pointed me to a few months ago. It has been
>> working perfectly as long as I had only one dictionary of keys mapping
>> to one dictionary of functions, but now I want two of each. My program
>> has different modes, which may have varying keystrokes, and I also
>> have some global keystrokes which are the same across all modes, like
>> exiting or switching modes. I cannot figure out how to make the
>> message loop look in two dictionaries at onc. I tried using an if,
>> saying that if action_to_take was not set in the mode-specific
>> dictionary then look at the global dictionary, but it is like it is
>> never looking in the global dictionary at all. I get no syntax errors
>> or problems when running the program, so it has to be something in my
>> logic. Go to
>> http://www.gateway2somewhere.com/sw/main.pyw
>> to see what I mean; the problem code is near the very bottom of the
>> file. Thanks for any suggestions. Oh, please note that I indent one
>> space per indentation level.
>>
> "msg.wParam" gives an int, but the keys of globalFuncs are 'g1', etc,
> not ints.
That did it. I originally used 1-4 like I did for the mode
dictionaries, not realizing that the ints were so important; I figured
they were just keys in the dictionary and that they could be anything,
it was just easier to use ints. Now, I have changed my globals to
20-23 and everything seems to be going well. Thanks!!
> Incidentally, you might want to change:
>
>  if(not action_to_take):
>
> to:
>
>  if action_to_take is None:
>
> in case any of the values happen to be 0 (if not now, then possibly at
> some time in the future).
Sorry, could you explain why you suggested this? I do not follow.
Because of the if statement "if action_to_take:", I figured it was
saying "if action_to_take was successfully set" or something else
having a boolean value. Guess not?
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


exiting threaded program?

2010-03-24 Thread Alex Hall
Hi all,
I have a program with a timer in it, therefore I have multiple
threads. My method of exiting by using "user32.PostQuitMessage (0)" no
longer seems to be doing the job since I added the timer. What else do
I have to do to close my program? I say it is not closing because,
before, I would be returned to a prompt in the cmd line, but now I
cannot type in the cmd line window even after the program supposedly
closes, whereas before I could have. Thanks.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using message loop for hotkey capturing

2010-03-24 Thread Alex Hall
Thanks, it seems to be working for now... Hopefully that trend continues!

On 3/24/10, Tim Golden  wrote:
> On 23/03/2010 17:01, Alex Hall wrote:
>> Hi all, but mainly Tim Golden:
>> Tim, I am using your wonderful message loop for keyboard input, the
>> one on your site that you pointed me to a few months ago. It has been
>> working perfectly as long as I had only one dictionary of keys mapping
>> to one dictionary of functions, but now I want two of each. My program
>> has different modes, which may have varying keystrokes, and I also
>> have some global keystrokes which are the same across all modes, like
>> exiting or switching modes. I cannot figure out how to make the
>> message loop look in two dictionaries at onc. I tried using an if,
>> saying that if action_to_take was not set in the mode-specific
>> dictionary then look at the global dictionary, but it is like it is
>> never looking in the global dictionary at all. I get no syntax errors
>> or problems when running the program, so it has to be something in my
>> logic.
>
> There's definitely some confusion, as MRAB picked up, with the
> globalkeys / globalfuncs thing. I can see no problem with simply
> defining an additional pair of dictionaries parallel with each of
> the keys/funcs dictionaries (note that the numbers are different
> from those of othe other dictionaries as these are the registration
> ids of the hotkeys):
>
> global_keys = {
>100: (68, win32com.MOD_ALT | win32con.MOD_CONTROL ...),
>...
> }
>
> global_funcs = {
>100 : dict.ShowLookupDialog,
>...
> }
>
> Then your central action code could be something like:
>
>action_to_take = global_funcs.get (msg.wParam) or HOTKEY_ACTIONS.get
> (msg.wParam)
>if action_to_take:
>  action_to_take ()
>
> This assumes that the funcs dictionaries will only ever contain a
> valid function, so the only possible Falsish value will arise from
> the get returning None.
>
> TJG
>
> BTW, you're shadowing a couple of builtins: global & dict which
> might give you problems later if you needed them. There are other
> issues with the structure of your code but nothing a little
> refactoring couldn't sort out if you felt so inclined.
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: exiting threaded program?

2010-03-24 Thread Alex Hall
A daemon... Good idea, and that makes more sense for what the thread
does anyway; it is just a timer, updating a variable by contacting a
server every hour. By the way, just what is the difference between
user32.PostQuitMessage (0) and sys.exit()?


On 3/24/10, Tim Golden  wrote:
> On 24/03/2010 10:43, Alex Hall wrote:
>> Hi all,
>> I have a program with a timer in it, therefore I have multiple
>> threads. My method of exiting by using "user32.PostQuitMessage (0)" no
>> longer seems to be doing the job since I added the timer. What else do
>> I have to do to close my program? I say it is not closing because,
>> before, I would be returned to a prompt in the cmd line, but now I
>> cannot type in the cmd line window even after the program supposedly
>> closes, whereas before I could have. Thanks.
>>
>
> Make the timer thread a daemon?
>
> TJG
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


timers not canceling!

2010-03-24 Thread Alex Hall
Hi all,
I am having trouble with a timer I am trying to use. It is the same
timer, but I need to cancel it when a certain event happens, then
start it again when a second event happens. The below is from a shell
session, not a file, but it shows my problem: I call cancel on a
timer, then call start on it, and it thinks it is already running?
What am I missing?

>>> from threading import Timer
>>> def func():
...  print("Time up!")
...
>>> t=Timer(10.0, func)
>>> t.start()
>>> t.cancel()
>>> t.start()
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\python26\lib\threading.py", line 465, in start
raise RuntimeError("thread already started")
RuntimeError: thread already started
>>>

I typed start, then typed cancel within ten seconds (probably four or
five), then called start again a couple seconds later. I figured
canceling the timer would kill the thread so I could start it again. I
am not looking for a reset, since I do not want it counting always.
Thanks.
-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


threads (specifically timers) and releasing resources

2010-03-24 Thread Alex Hall
Okay, I have my program and it has three different modes (there will
be more than that). Each mode will have a timer attached to it. If the
mode remains active and the timer runs out, a function specific to
that mode is called. If that mode is switched away from, however, the
timer is canceled and a new timer is created for the mode to which the
user just switched. My question is: what happens with resources taken
up by previous timers, whether they cancel or execute? I would hate
for my program to run for a long time and slowly build up a massive
list of old threads (timers), taking up resources which should have
been released. Will Python perform GC and completely erase a thread
once it is done, or will it keep hanging around? If the latter, is
there a way to completely destroy a thread? Thanks; Google was not too
helpful on this one!

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: threads (specifically timers) and releasing resources

2010-03-25 Thread Alex Hall
Thanks, this should work.

On 3/25/10, Tim Golden  wrote:
> On 25/03/2010 02:31, Alex Hall wrote:
>> Okay, I have my program and it has three different modes (there will
>> be more than that). Each mode will have a timer attached to it. If the
>> mode remains active and the timer runs out, a function specific to
>> that mode is called. If that mode is switched away from, however, the
>> timer is canceled and a new timer is created for the mode to which the
>> user just switched.
>
> I assume you're using Python's threading.Timer objects as you'd discussed
> those before. If so, that's basically a threading.Thread in disguise.
> In which case, you're going to have to make sure it cleans up after itself,
> releasing whatever resources it holds.
>
> Python's reference-count semantics and cyclic gc will take care of
> things in the normal way once the timer-thread has completed. But
> you'll have to make sure it completes.
>
>> If the latter, is there a way to completely destroy a thread?
>
> No: in Python, a thread has to self-destruct. This is a relatively
> FAQ and there are quite a few recipes around. Here's an example of
> something which seems to be close to your current needs:
>
> http://code.activestate.com/recipes/464959-resettable-timer-class/
>
> TJG
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Have you embraced Python 3.x yet?

2010-03-26 Thread Alex Hall
Because of compatibility, and many modules being built for 2.6 only, I
am still on 2.6.4 (updating to .5 soon).

On 3/26/10, Harishankar  wrote:
> Have you people embraced Python 3.x or still with 2.5 or 2.6?
>
> I personally want to switch over but not too sure how many people are
> using 3.x as opposed to 2 so I want to keep my programs compatible for
> the majority.
>
> -- Hari
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


imports again

2010-04-06 Thread Alex Hall
Sorry this is a forward (long story involving a braille notetaker's
bad copy/paste and GMail's annoying mobile site). Basically, I am
getting errors when I run the project at
http://www.gateway2somewhere.com/sw.zip
and I do not understand why. The bad line was working until I added
more import statements. I know my setup is not good, but I cannot seem
to get my own packages to work (putting files in a folder along with
__init__.py). If anyone can explain what I did and how I can fix it, I
would very much appreciate it!! Requires Windows, tested on Vista/xp/7
with python2.6.

-- Forwarded message ------
From: Alex Hall 
Date: Tue, 6 Apr 2010 13:06:24 -0400
Subject: imports again
To: python-us...@python.org

Hello all,
My project is stalled because of an import problem. I know my imports
are a tangled mess (1 imports 2 3 and 4, 2 imports 1 and 3, 3 imports
2 and 4, and so on). I would very much appreciate it if someone could
look at the setup and recommend a fix. Right now, an exception is
being thrown when I import a file, even though this import was working
until I added some different import statements. The entire thing,
intended for Windows xp+ and Python2.6, is at
http://www.gateway2somewhere.com/sw.zip
Thanks in advance for any help or suggestions!

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap



-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Imports again...

2010-04-09 Thread Alex Hall
Hello all, once again:
http://www.gateway2somewhere.com/sw/sw.zip

The above link is to a project. I am new to using multiple files in
Python, and I have a lot of tangled imports where many files in the
same folder are importing each other. When I tried to follow the
manual to make some files into packages, it did not work. Can anyone
explain why I am getting an import error in the above project, and/or
how I can clean up the file structure and imports to avoid problems
like this in the future? Thanks in advance for any help, and I
apologize for the broken link the other day.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Imports again...

2010-04-09 Thread Alex Hall
Okay, what you all say makes sense, and I am going to try the package
thing again. The "modes" dir is from my last attempt, as is its
"weather" subdir. I think I see what I did wrong, at least I hope I
do. I will also remove the init file from the main dir. Yes, "arm" is
the main directory of the program. Also, I will try to update things
so that most imports happen from the dependencies folder, avoiding the
need to install/copy so much to your local install of Python. Here is
a traceback of the program as it is right now; this is from the exact
same version as the .zip file contains.

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Alex>cd c:\python26

c:\Python26>python.exe i:\arm\main.pyw
Traceback (most recent call last):
  File "i:\arm\main.pyw", line 3, in 
import arm, network, weather, dict
  File "i:\arm\arm.py", line 4, in 
import config
  File "i:\arm\config.py", line 4, in 
from main import exitProgram
  File "i:\arm\main.pyw", line 3, in 
import arm, network, weather, dict
  File "i:\arm\network.py", line 4, in 
arm.ready()
AttributeError: 'module' object has no attribute 'ready'

c:\Python26>


I realize it may be odd to import from main.pyw, but I do not think
that could be causing the problem... could it? Perhaps I should erase
all the .pyc files and let it compile again, or would that not do
anything?

On 4/9/10, Tim Golden  wrote:
> On 09/04/2010 15:19, Gabriel Genellina wrote:
>> In addition to what Tim Golden has said (which appears to be based on
>> another
>> version of this project
>
> Just downloaded again, and there's definitely an empty package structure
> of the kind I described. (Altho' I certainly did have a few other versions
> lying around from previous questions by the OP).
>
>> Also, you have some .pyw files with corresponding .pyc file. That's *very*
>> strange. .pyw files are *not* modules, and Python won't import them.
>
> Ahem.
>
> 
> Python 2.6.4rc2 (r264rc2:75501, Oct 18 2009, 22:41:58) [MSC v.1500 32 bit (I
> Type "help", "copyright", "credits" or "license" for more information.
 open ("xxx.pyw", "w").write ("print ('hello')")
 import xxx
> hello


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


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: On Class namespaces, calling methods

2010-04-10 Thread Alex Hall
On 4/10/10, vsoler  wrote:
> Still learning python, especially OOP.
>
> While testing classes, I sometimes think of them as "ordinary
> containers" of values and functions (methods). That is, values and
> functions can be grouped together inside "namespaces" calles classes.
>
> class Uno:
> a=1
> def m():
def m(self):
> print "mouse"
  print "mouse" #I believe
>
> Say that I have this "silly" class.
>
> While I can then write
>
>   print Uno.a
>
> I cannot write
>   Uno.m()
>
> I get the following error message:
>
>  TypeError: m() takes no arguments (1 given)
>
> Since I have not created any instances of Uno, there is no self
> object, and I do not understand what object is supplied to the
> function call.
I believe that self is always passed, whether you have an instance of
the uno class or not. Since you did not tell m() to expect self to be
passed to it, and self is passed anyway, m() has this self and has no
idea what to do with it. Also, you must make an uno object (u=uno())
then call methods off that object (u.m()) since not doing so means the
uno class will not get initialized.
>
> Could anybody explain what argument is being supplied to the method?
> Is ther any workaround to call the m function?
>
> Thank you
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


curious about python version numbers

2010-04-13 Thread Alex Hall
Hi all,
I am just curious: if Python3.x is already out, why is 2.7 being
released? Are there two main types of Python? Thanks.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


packaging multiple python scripts as Windows exe file

2010-04-13 Thread Alex Hall
Hi all,
While my project is still suffering from major import problems, I will
soon have to try to package it as a Windows executable file. I do not
want an installer; I want the user to be able to run the program for
as long as they want, then to quit (by using a command from inside the
program) and that is it. Nothing to install, no files to copy, no
registry editing, just start and use it until done.

I know about the popular solutions for this sort of thing, but I read
that a DLL is required, and that this dll cannot be (legally)
distributed by myself? A few questions here:
1. Did I read this wrong / is this outdated? Please answer 'yes' as
this will be a real pain to deal with.

2. If I must have it but can distribute it, where should it go so my
program can find it?

3. If the user must download it for legal reasons, instead of me
giving it to them, can I just have a Python script take care of it and
put it in the same directory as the program, so the program can find
it, or do I need to register the dll with the system? If I need to
register, does this require admin login?

Thanks as always!

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: curious about python version numbers

2010-04-13 Thread Alex Hall
Thanks, everyone, for the answers! I am still on 2.6 since so many
packages rely on it. I got 3.1 at first, but I could not get much to
work with it so I installed 2.6 and have only found one package which
refuses to work, instead of a lot of them.

On 4/13/10, Shashwat Anand  wrote:
> It is like releasing window Xp SP3 even if Vista is out.
>
> The problem is we should start using python 3.x but many application like
> django, twisted had not migrated yet. Hence this stuff to support 2.x . 2.7
> is the last 2.x version, no more.
>
> On Tue, Apr 13, 2010 at 2:28 PM, Alf P. Steinbach  wrote:
>
>> * Alex Hall:
>>
>>  Hi all,
>>> I am just curious: if Python3.x is already out, why is 2.7 being
>>> released? Are there two main types of Python? Thanks.
>>>
>>
>> Old code and old programming habits may work as-is with 2.7 but not with a
>> 3.x implementation.
>>
>> So yes, there are two main extant variants of Python, 2.x and 3.x (and
>> more
>> if you count even earlier versions).
>>
>> 2.7 helps to ease the transition, and provides bug-fixes and better
>> efficiency for the 2.x variant.
>>
>>
>> Cheers & hth.,
>>
>> - Alf
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: packaging multiple python scripts as Windows exe file

2010-04-14 Thread Alex Hall
msvcr90.dll is the file, and, according to the py2exe tutorial, step
5, I do not have permision to distribute the file. This is not good
news, but beyond that, I apparently get an entire directory with all
required files, not a single .exe which has everything packaged inside
it. Is there another way of compiling Python to .exe which gives me
one file containing all my dlls and Python dependencies? If not then a
folder is not bad, but a single file would be best.

On 4/13/10, Joaquin Abian  wrote:
> On Apr 13, 9:56 pm, Mike Driscoll  wrote:
>> On Apr 12, 5:20 pm, Alex Hall  wrote:
>>
>>
>>
>> > Hi all,
>> > While my project is still suffering from major import problems, I will
>> > soon have to try to package it as a Windows executable file. I do not
>> > want an installer; I want the user to be able to run the program for
>> > as long as they want, then to quit (by using a command from inside the
>> > program) and that is it. Nothing to install, no files to copy, no
>> > registry editing, just start and use it until done.
>>
>> > I know about the popular solutions for this sort of thing, but I read
>> > that a DLL is required, and that this dll cannot be (legally)
>> > distributed by myself? A few questions here:
>> > 1. Did I read this wrong / is this outdated? Please answer 'yes' as
>> > this will be a real pain to deal with.
>>
>> > 2. If I must have it but can distribute it, where should it go so my
>> > program can find it?
>>
>> > 3. If the user must download it for legal reasons, instead of me
>> > giving it to them, can I just have a Python script take care of it and
>> > put it in the same directory as the program, so the program can find
>> > it, or do I need to register the dll with the system? If I need to
>> > register, does this require admin login?
>>
>> > Thanks as always!
>>
>> > --
>> > Have a great day,
>> > Alex (msg sent from GMail website)
>> > mehg...@gmail.com;http://www.facebook.com/mehgcap
>>
>> Without knowing the exact DLL you're thinking of, we can't be sure
>> what the answer is. But I think you're talking about a certain MS DLL
>> that Python distributes. If so, I've read multiple threads on this
>> topic that claim that since Python distributes it, there is an implied
>> permission that you can as well. Since I'm not a lawyer, I can't say
>> for sure, but the articles I've seen are pretty convincing.
>>
>> ---
>> Mike Driscoll
>>
>> Blog:  http://blog.pythonlibrary.org
>
> the OP probably means MSVCR71.dll that is needed to make single file
> executables with py2exe.
> This has been discussed elsewhere. Look at
> http://www.py2exe.org/index.cgi/Tutorial#Step5
>
> joaquin
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


msvcr90.dll is MIA?

2010-04-14 Thread Alex Hall
Hi all,
For testing purposes, and because I am not yet distributing my
application (which, thanks to you all, is now running perfectly!), I
am going to just bundle msvcr90.dll. However, I cannot find it! I ran
vcredist_x86.exe (I have a 64-bit version of win7, but all I have is
the x86 version of the program - is that a problem?). A search for
msvcr90.dll and just vcr90.dll returns 0 results. Where did it put my
msvcr90.dll file? I thought the point was to give me the dll? Thanks.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


missing dll follow-up

2010-04-14 Thread Alex Hall
Hi again,
I said "msvcr90.dll", but I meant "msvcp90.dll". In either case, I
cannot locate the dll to include in my project and I am not sure what
else I can do. The vcredist_x86 was, I thought, supposed to give me
the dll, but it does not seem to have done so.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: msvcr90.dll is MIA?

2010-04-14 Thread Alex Hall
I tried both vcredist_x86.exe and vcredist_x64.exe, with no result; I
still do not have the required dll (I have 32-bit python, so the _x86
should have done the trick). I will try another poster's suggestion of
installing vcpp express 2005 and hope that will work...

On 4/14/10, Gabriel Genellina  wrote:
> En Wed, 14 Apr 2010 00:07:48 -0300, Alex Hall  escribió:
>
>> For testing purposes, and because I am not yet distributing my
>> application (which, thanks to you all, is now running perfectly!), I
>> am going to just bundle msvcr90.dll. However, I cannot find it! I ran
>> vcredist_x86.exe (I have a 64-bit version of win7, but all I have is
>> the x86 version of the program - is that a problem?). A search for
>> msvcr90.dll and just vcr90.dll returns 0 results. Where did it put my
>> msvcr90.dll file? I thought the point was to give me the dll? Thanks.
>
> You need the same architecture and version as used by Python itself. A
> 32-bit executable (Python, or your compiled program) requires a 32-bit
> dll, a 64-bit executable requires a 64-bit dll (and this one comes from a
> different redistributable package, vcredist_x64.exe).
> You may install the 32-bit dlls on a 64-bit Windows, but only 32-bit
> programs will be able to use it.
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: msvcr90.dll is MIA?

2010-04-14 Thread Alex Hall
I notice that I do not have the dll when py2exe says it cannot locate
the dll. If I need vs2008, then what good is vcredist_xxx.exe? It does
not seem to give me the dll, but the py2exe tutorial says that it
will. What am I missing?

On 4/14/10, Christian Heimes  wrote:
> On 14.04.2010 13:22, Alex Hall wrote:
>> I tried both vcredist_x86.exe and vcredist_x64.exe, with no result; I
>> still do not have the required dll (I have 32-bit python, so the _x86
>> should have done the trick). I will try another poster's suggestion of
>> installing vcpp express 2005 and hope that will work...
>
> How do you notice that you don't have the required DLL? The DLLs aren't
> copied into system32. The new location is the side by side assembly
> directory WinSxS. You need adminstration privileges to install SxS
> assemblies.
>
> By the way VC Express 2005 is the wrong version. Python 2.6 and newer
> are compiled with VS 2008.
>
> Christian
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: msvcr90.dll is MIA?

2010-04-14 Thread Alex Hall
On 4/14/10, Christian Heimes  wrote:
> On 14.04.2010 14:25, Alex Hall wrote:
>> I notice that I do not have the dll when py2exe says it cannot locate
>> the dll. If I need vs2008, then what good is vcredist_xxx.exe? It does
>> not seem to give me the dll, but the py2exe tutorial says that it
>> will. What am I missing?
>
> Do you have the correct vcredist for VS 2008?
I ran the redist exe from Microsoft that said it was for c++ 2008, from
http://www.microsoft.com/downloads/details.aspx?FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1bf&displaylang=en
I still cannot find the dll I need! Again, I have 32-bit python2.6 on
win7x64, so I got the _x86 version of the redist file. I have also
tried running the x64 version of the file, just to see if it would
help, but I still have no dll. I installed vs2005, but apparently I
need vs2008, which I cannot find.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: msvcr90.dll is MIA?

2010-04-14 Thread Alex Hall
On 4/14/10, Enrico  wrote:
> Il 14/04/2010 14:25, Alex Hall ha scritto:
>> I notice that I do not have the dll when py2exe says it cannot locate
>> the dll. If I need vs2008, then what good is vcredist_xxx.exe? It does
>> not seem to give me the dll, but the py2exe tutorial says that it
>> will. What am I missing?
>
> Alex, the DLLs are in winsxs, try searching there.
They are not there, unless I am in the wrong folder. I searched in
c:\windows\winsxs.
> For py2exe, it doesn't find the DLLs so you should provide them. In my
> setup.py (I use also the wxPython lib so something could be different) I
> added:
>
> def isSystemDLL(pathname):
>  if os.path.basename(pathname).lower() in ('msvcp90.dll'):
>  return 0
>  return origIsSystemDLL(pathname)
> origIsSystemDLL = py2exe.build_exe.isSystemDLL
> py2exe.build_exe.isSystemDLL = isSystemDLL
>
> Then I added to 'dll_excludes' the same 'msvcp90.dll'.
>
> In this way py2exe is ok without this DLL and can build the excutable.
> Note that the dll that py2exe is looking for is msvcp90 in my case.
>
> Then I added a subdirectory with the DLLs (msvcr90, msvcp90, msvcm90) to
> the distribution directory. You need a manifest too :-)
>
> Ok, it seems complex but you can check the followings
> http://www.py2exe.org/index.cgi/Tutorial
I have looked there, that is where I got the redist exe file which did
not work. I then went and got a copy of the file right from Microsoft,
but no luck there either.
> http://wiki.wxpython.org/py2exe (related to wxPython but look at the
> manifest)
>
> An other solution is to run the vcredist on the target machine and the
> application will run. This is the suggested solution if you cannot
> distibute the DLLs.
I cannot distribute them. So you are saying to compile without the
dll, then run the redist file? I would much rather package everything
as this is meant to be a stand-alone app, runable from anywhere (even
a thumb drive on a computer on which you are a guest, like a hotel or
library machine). It is not meant to install anything or copy any
files, just run in memory and then close when the user decides to
close.
>
> Bye, Enrico
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Updated License Term Agreement for VC Redistributable in VS 2008 SP1

2010-04-14 Thread Alex Hall
I do not see anything about redistribution, only installation, unless
I am missing something?

On 4/14/10, pyt...@bdurham.com  wrote:
> I just stumbled across the following page which seems to indicate that
> the MS VC 2008 runtime files[1] required to distribute Python
> applications compiled with Py2exe and similar tools can be shipped
> without the license restriction many previously thought.
>
> See: Updated License Term Agreement for VC Redistributable in VS 2008
> SP1
> http://code.msdn.microsoft.com/KB956414
>
> 
> The End User License Agreement (EULA) attached to the English version of
> Visual C++ (VC) Redistributable Package (VCRedistx86.exe,
> VCRedistx64.exe, and VCRedist_ia64.exe) in Microsoft Visual Studio 2008
> does not let you redistribute the VC Redist files. It specifies that you
> may only install and use one copy of the software.
>
> > The correct EULA allows installation and use of any number of
> copies of the VC Redist packages. <
>
> CAUSE
>
> This problem occurs when Visual Studio 2008 SP1 installs incorrect VC
> Redist files that have the wrong EULAs to the computer.
> 
>
> I know there's been lots of confusion about whether developers can ship
> these DLL files directly or whether developers must ship the Visual C++
> 2008 Redistributable Package SP 1 files (vcredist_x86.exe or
> vcredist_x64.exe) - I think the above article should settle this debate
> once and for all.
>
> Malcolm
>
> 1. MS VC 2008 runtime files: msvcr90.dll, msvcp90.dll, msvcm90.dll
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


py2exe and msvcp90.dll

2010-04-15 Thread Alex Hall
Hi all,
I am still fighting with py2exe; I keep getting "error: msvcp90.dll:
no such file or directory" right after it says it is searching for
required dlls. I have followed the py2exe tutorial, though, and I am
not sure why it is not finding the dlls, which are in both
c:\windows\system32 and in mainFolder/dlls, where mainFolder is the
main folder of my project, containing setup.py. Here is my setup file:

from distutils.core import setup
import py2exe
from glob import glob
data_files=[("Microsoft.VC90.CRT", glob(r'c:\arm\dlls\*.*'))]
setup(data_files=data_files, console=['main.pyw'])

Of course, the location to glob is hard-coded. Also, I do not intend
this to have any console. Can I just omit the console argument? I
leave it in for now since the tutorial seems to indicate that such a
file is necessary, but I do not want to have one eventually. Thanks in
advance, as always! Oh, the entire source is at
http://www.gateway2somewhere.com/sw/sw.zip
as it usually is (and this time, I tested the link!).


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


py2exe saga continues...

2010-04-15 Thread Alex Hall
Hi all,
I started a new thread as I already have several out there, all
talking about basically the same thing. After re-visiting a
StackOverflow post, thanks to the person who gave me that link, I
tossed msvcp90.dll and msvcr90.dll (I use wx) into c:\python26\dlls
and it now compiles! I think I kept thinking that all I needed was to
have the dll files in *my own program folder*. I now have an exe file
which, after doing more globbing of a configuration file and some
other dlls I need, does exactly what I wanted it to do. I now have a
couple questions so I can fine-tune this:
1. Is there a way to start with no command line window popping up? My
main script is a pyw, but it still shows a dos window when the
generated .exe file is clicked. Leaving out the "console" parameter of
setup, though, results in no .exe file at all, so I had to put it
back. I want what I have heard called a "silent startup", where the
program starts but it does not pop up anything. My users will know
because I will speak a message, but I want to dump the dos window.

2. Is there a way to put the exe in a higher-level dir, then put all
the pyd, dll, zip, and other files into a subdirectory so the .exe is
not mixed in with all these files that most users will not care about?
Thank you for all your help over the last few days!!

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe saga continues...

2010-04-15 Thread Alex Hall
On 4/15/10, Mark Hammond  wrote:
> On 16/04/2010 10:52 AM, Alex Hall wrote:
>> 1. Is there a way to start with no command line window popping up? My
>> main script is a pyw, but it still shows a dos window when the
>> generated .exe file is clicked. Leaving out the "console" parameter of
>> setup, though, results in no .exe file at all, so I had to put it
>> back. I want what I have heard called a "silent startup", where the
>> program starts but it does not pop up anything. My users will know
>> because I will speak a message, but I want to dump the dos window.
>
> You probably want to use the 'windows=' option instead of the 'console='
> option (or both if you like - in which case you probably also need to
> specify a 'dest_base' value for one of them.
Yes, that did it!
>
>> 2. Is there a way to put the exe in a higher-level dir, then put all
>> the pyd, dll, zip, and other files into a subdirectory so the .exe is
>> not mixed in with all these files that most users will not care about?
>> Thank you for all your help over the last few days!!
>
> I *think* that if you specify the 'zipfile' param to include a directory
> portion then all libs will be stored in that same dir.  Eg, spambayes
> includes:
>
>zipfile = "lib/spambayes.modules",
>
> which causes the .zip file to be named as specified, but all the .pyd
> files also wind up in the 'lib' directory.  Use of the 'dest_base' param
> causes all executables to be placed in a 'bin' directory, so we have 2
> separate dirs holding things.
I found that setting zipfile to None gets rid of an unnecessary (as
far as I can tell) .zip file; specifying another name did not do
anything, though it did not give me an error either.
> Spambayes has a complicated setup file
> which may offer some insights - find the spambayes source at sourceforge
> then look for the spambayes/spambayes/windows/py2exe/setup_all.py file
> for inspiration...

Oddly, I set the --bundle flag to 1, then 2, but in both cases my
program had a memory error. When the bundle flag was left out, I have
no errors and things work as expected. In either case, though, I get a
dist folder of nearly 21mb in size, much larger than I ever imagined!
I use wx, wmi, win32con, and ctypes (and other libs, but they are
small). Is there any way of optimizing things so that I can get the
overall size down some?
>
> HTH,
Yes, it helped a lot.
>
> Mark.
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


py2exe breaking wxPython?

2010-04-24 Thread Alex Hall
Hello all,
I have a compiled version of my project, but the wx functions do not
work. When run from the python source, instead of the compiled .exe
file, wx works as expected. I am including msvcr90.dll in the dist
folder. I looked for answers on Google, but I could not really follow
the tutorials and forums I found. Is there a simple fix for this? BTW,
I am still using py2exe and python2.6. Here is the traceback I get
when using the .exe version of the project and calling a wx operation:

Traceback (most recent call last):
  File "sw.pyw", line 217, in 
  File "dict.pyc", line 73, in showLookupDialog
  File "wx\_core.pyc", line 7978, in __init__
  File "wx\_core.pyc", line 7552, in _BootstrapApp
  File "dict.pyc", line 26, in OnInit
AttributeError: 'NoneType' object has no attribute 'Bind'
Traceback (most recent call last):
  File "sw.pyw", line 217, in 
  File "dict.pyc", line 73, in showLookupDialog
  File "wx\_core.pyc", line 7978, in __init__
  File "wx\_core.pyc", line 7552, in _BootstrapApp
  File "dict.pyc", line 26, in OnInit
AttributeError: 'NoneType' object has no attribute 'Bind'

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


dll errors in compiled python program

2010-04-29 Thread Alex Hall
Hi all,
I am stumped. The compiled version of my project works on my pc, but
when I put it on a thumb drive and try it on a laptop without python
installed I get this:

Traceback (most recent call last):
  File "sw.pyw", line 3, in 
  File "modes\arm.pyc", line 4, in 
  File "dependencies\wmi1_3\wmi.pyc", line 140, in 
  File "win32com\__init__.pyc", line 5, in 
  File "win32api.pyc", line 12, in 
  File "win32api.pyc", line 10, in __load
ImportError: DLL load failed: The specified procedure could not be found.
Traceback (most recent call last):
  File "sw.pyw", line 3, in 
  File "modes\arm.pyc", line 4, in 
  File "dependencies\wmi1_3\wmi.pyc", line 140, in 
  File "win32com\__init__.pyc", line 5, in 
  File "win32api.pyc", line 12, in 
  File "win32api.pyc", line 10, in __load
ImportError: DLL load failed: The specified procedure could not be found.

It repeated it twice in the log file; that is no mistake. The compiled exe is at
http://www.gateway2soemewhere.com/sw/sw_beta.zip

Thanks in advance. I will be amazed when this finally works the way it should!!


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


RESOLVED Re: dll errors in compiled python program

2010-04-29 Thread Alex Hall
Thanks for the suggestion. It turns out that the problem was a copy of
fowprof.dll, or something like that, which win7 included in my
compiled program's dir. I was testing the program on xp, which has its
own version of this dll, so deleting the dll from the dir solved it.

On 4/29/10, alex23  wrote:
> Alex Hall  wrote:
>> I am stumped. The compiled version of my project works on my pc, but
>> when I put it on a thumb drive and try it on a laptop without python
>> installed I get this:
>> ImportError: DLL load failed: The specified procedure could not be found.
>
> Are you using py2exe? If so, are you including the necessary MS
> runtime dll[1]?
>
> 1: http://www.py2exe.org/index.cgi/Tutorial#Step5
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


does this exception mean something else?

2010-05-06 Thread Alex Hall
Hi all,
I have a file, pasted below for what good it will do, which makes a
couple conditional calls to a function called writeDefaults. However,
when I manually trigger a condition that causes the function to be
called, Python gives me a name error and says that my writeDefaults
does not exist. I am sure that it does, as I copied the text from the
call and pasted it into the text search of my editor, and it found the
line that defines the function, so the text in the call is obviously
correct. Sometimes, especially in a language like Javascript, one
error can mean something else or point to a problem other than the one
it claims to be about, so I wondered if the same thing could be
happening here? The error is on line 55, just after the if statement
that uses os.path.exists to ensure my ini file is really there. TIA!
BTW, speech is just a file that will output a given message through an
active screen reader; changing all calls to print will work just as
well.

import os, sys
import helpers
from configobj import ConfigObj #for reading ini files
from string import Template #for interpreting the template strings in
the ini file
from speech import speak

#set up a default dict of options to be used
general={
 "useSpeech":"True",
 "printMessages":"False",
 "roundTo":1,
 "defaultStartMode":1
}

enableModes={
 "resourceMonitor":"True",
 "weather":"True",
 "network":"True"
}

weatherOptions={
 "location":"04938"
}

armOptions={
 "primaryDrive":"c:",
 "secondaryDrive":"j:",
 "currentIsPrimary":"True",
 "CIsSecondary":"True",
 "ramInfo":"used",
 "driveInfo":"Used"
}

templates={
 "sayCorePercentage":"$percent% for core $core",
 "sayProcessorAverage":"$percent% average load",
 "sayRamFree":"$percent% ram free ($free of $total remaining)",
 "sayRamUsed":"$percent% ram used ($used of $total used)",
 "sayDriveFree":"$percent% free on $drive ($free of $total remaining)",
 "sayDriveUsed":"$percent% used on $drive ($used of $total used)",
 "currentWeather":"$condition, $temp degrees. $wind. $humidity.",
 "forecast":"$day: $condition, $low to $high."
}


#first, load the ini file setting
#so where is the ini? script_path/config.ini, of course!
iniLoc=helpers.progdir+'\\config.ini'
iniLoc=r'c:\arm\config.ni'
#set up the ini object to read and write settings
if(os.path.exists(iniLoc)):
 ini=ConfigObj(iniLoc)
else:
 speak("The i n i file was not found. Now generating a default file.")
 writeDefaults()
#end except

#now get the settings
general=ini["general"]
printMessages=general["printMessages"]
speech=general["useSpeech"]
rnd=int(general["roundTo"])
mode=int(general["defaultStartMode"])

enable=ini['enableModes']
rmOn=enable["resourceMonitor"]
weatherOn=enable["weather"]
networkOn=enable["network"]

aop=ini["armOptions"] #the options section
drive1=aop["primaryDrive"]
drive2=aop["secondaryDrive"]
ramInfo=aop["ramInfo"]
driveInfo=aop["driveInfo"]
useCurrentDrive=aop["currentIsPrimary"]
CIsSecondary=aop["CIsSecondary"]

wop=ini["weatherOptions"]
zip=str(wop["location"])

subs=ini["templates"] #short for substitute
corePercent=Template(subs["sayCorePercentage"])
avg=Template(subs["sayProcessorAverage"])
sayRamFree=Template(subs["sayRamFree"])
sayRamUsed=Template(subs["sayRamUsed"])
sayDriveFree=Template(subs["sayDriveFree"])
sayDriveUsed=Template(subs["sayDriveUsed"])
currentWeather=Template(subs["currentWeather"])
forecast=Template(subs["forecast"])

def setOptions():
 global ini
 try:
  ini.reload()
 except:
  speak("The i n i file was not found. Now generating a default file.")
  writeDefaults()
 #end except
 #now just a few settings that depend on the options
 #if useCurrentDrive is true, get that drive and set drive1 to it
 if(useCurrentDrive=="True"):
  #get current drive and assign it to primary
  currentDrive=os.path.splitdrive(sys.argv[0])[0]
  drive1=currentDrive
  #furthermore, if CIsSecondary is true, set that here,
  #since useCurrentDrive must be true for this one to take effect
  if(CIsSecondary=="True"):
   drive2="c:"
  #endif
 #endif
#end def

def writeDefaults():
 global ini
 global iniLoc
 ini.filename=iniLoc
 ini["general"]=general
 ini["enableModes"]=enableModes
 ini["weatherOptions"]=weatherOptions
 ini["armOptions"]=armOptions
 ini["templates"]=templates
 #create the new file
 ini.write()
#end def

def speakSetOptions():
 #just calls setOptions, but I use this separate def so I can speak a
"reloaded" msg
 setOptions()
 speak("Settings reloaded.")
#end def

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: does this exception mean something else?

2010-05-06 Thread Alex Hall
Changing the order so the function is first did it. Thanks. That is
what I get for working with Java all semester...

On 5/6/10, MRAB  wrote:
> Alex Hall wrote:
>> Hi all,
>> I have a file, pasted below for what good it will do, which makes a
>> couple conditional calls to a function called writeDefaults. However,
>> when I manually trigger a condition that causes the function to be
>> called, Python gives me a name error and says that my writeDefaults
>> does not exist. I am sure that it does, as I copied the text from the
>> call and pasted it into the text search of my editor, and it found the
>> line that defines the function, so the text in the call is obviously
>> correct. Sometimes, especially in a language like Javascript, one
>> error can mean something else or point to a problem other than the one
>> it claims to be about, so I wondered if the same thing could be
>> happening here? The error is on line 55, just after the if statement
>> that uses os.path.exists to ensure my ini file is really there. TIA!
>> BTW, speech is just a file that will output a given message through an
>> active screen reader; changing all calls to print will work just as
>> well.
>>
> You need to remember that 'def' and 'class' are _statements_, not
> declarations; they have the side-effect of adding a name to the current
> namespace.
>
> A Python script is run from the first line. If/when Python reaches line
> 55 the 'def' statement that defines the function 'writeDefaults' hasn't
> been run yet.
>
> BTW, you should avoid 'bare excepts' (an except clause that doesn't say
> which exception to catch) because they catch _every_ exception, even
> KeyboardInterrupt and NameError.
>
> You might also want to look at PEP 8:
>
>  http://www.python.org/dev/peps/pep-0008/
>
> which is the Style Guide for Python code.
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: importing modules

2010-05-07 Thread Alex Hall
I have a main folder. Inside that I have a "modes" package (subfolder
holding __init__.py) as well as a "misc" package. When modes has to
import helpers.py from misc, I use this:
from .misc import helpers
The period makes Python look up one level for misc, then go into it to
find helpers.

On 5/7/10, Richard Lamboj  wrote:
>
> Hello,
>
> I have a question about importing python modules.
>
> I have modul package, with submodules. So how can a  submodul access a modul
> that is on level upper?
>
> Is there something like "import ../../blah"? I don't mean something like
> this: "import bla.blub.moep"
>
> Kind Regards,
>
> Richi
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


shortcut for large amount of global var declarations?

2010-05-08 Thread Alex Hall
Hi all,
I am sorry if this is the second message about this you get; I typed
this and hit send (on gmail website) but I got a 404 error, so I am
not sure if the previous message made it out or not.
Anyway, I have about fifteen vars in a function which have to be
global. Is there a faster and more space-efficient way of doing this
than putting each var on its own line; that is, fifteen "global
varName" declarations? Thanks.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shortcut for large amount of global var declarations?

2010-05-08 Thread Alex Hall
On 5/8/10, Jon Clements  wrote:
> On 8 May, 15:08, Alex Hall  wrote:
>> Hi all,
>> I am sorry if this is the second message about this you get; I typed
>> this and hit send (on gmail website) but I got a 404 error, so I am
>> not sure if the previous message made it out or not.
>> Anyway, I have about fifteen vars in a function which have to be
>> global. Is there a faster and more space-efficient way of doing this
>> than putting each var on its own line; that is, fifteen "global
>> varName" declarations? Thanks.
>>
>> --
>> Have a great day,
>> Alex (msg sent from GMail website)
>> mehg...@gmail.com;http://www.facebook.com/mehgcap
>
> About 15 that *need* to be global; smells bad to me. However, you can
> amend a function's .func_globals attribute.
How do you do this exactly?
> Just wouldn't be going there myself. Why do you have this many? What's your
> use case?
They are in a "setOptions" function in config.py, which reads from an
ini file and sets up all options for the program. All other files then
can read these options. For example, anyone else can import config,
then, if they are rounding a number, they can know how many places to
round to by looking at config.rnd. I have everything in a function
instead of being initialized upon importing since I offer a function
to reload the ini file if the user changes something. Eventually I
will have a gui for setting options, and that gui, to save options,
will write an ini file then call setOptions so all options are then
reset according to the newly created ini. If I do not make everything
in setOptions global, no other file seems able to read it; I get an
exception the first time another file tries to access a setting.
Thanks.
>
> Jon.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Data store solution need help

2010-05-14 Thread Alex Hall
An important question is: will you need this input stored across
multiple runs of the program? What I mean is, do you want the user to
set the data, then have those same settings even after closing and
re-opening the program?

On 5/14/10, Bruno Desthuilliers
 wrote:
> Haulyn Jason a écrit :
>> Hi, all:
>>
>> I am a Java programmer, now I am working on a Python program. At the
>> moment, I need to store some data from user's input, no database, no
>> xml, no txt(we can not make users open the data file by vim or other
>> text editor).
>>
>> Any suggestions or reference url? Is there a lib should do this or I
>> need to implement it myself?
>>
>> PS: if I want to implement it myself, which part of python document I
>> need to learn? I know how to write txt files now, but not further for me.
>>
>
> Not sure I really understand whether you want to store your data in just
> any format or if it need to be a "binary" format or else... And you
> don't tell much about how your data structure and how it will be used.
>
> Anyway: two possible solutions are csv or serialization.
>
> For the first option, see the csv module
> http://docs.python.org/library/csv.html#module-csv
>
> For the second, look at pickle and shelve modules:
> http://docs.python.org/library/pickle.html#module-pickle
> http://docs.python.org/library/shelve.html#module-shelve
>
>
> If none of this fits your needs, please provide more details !-)
> HTH
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


tone generation for motherboard and sound card speakers?

2010-05-16 Thread Alex Hall
Hi all,
I am wondering if there is a way to generate a tone for the
motherboard speaker, like the call to Beep() in C++?

Also, is there a module to generate tones in Python using the sound
card? A module that can beep at a given frequency for a given time
using the usual sine wave is okay, but the fancier the better
(different waves, sweeping, and so on).

My final question will likely hinge upon the answer to the second
question, but is there a way to play a tone in a given position in the
stereo field? For example, I have a Battleship tactical board (my name
for where the little red and white pins go) which I am trying to
sonify using different tones for each status (not fired on, ship
sighted, ship hit, ship sunk). I want each row to play, from top to
bottom, but each square in each row should start at the left and
continue to the last square playing in the right speaker, giving the
user a better idea of where each square is. Oh, this is for blind
users, in case you were wondering why anyone would want to sonify a
battleship board.
Thanks for any information, and note that I am using Python2.6; unless
there is an easy way to use a module meant for 2.5 or before inside a
2.6 project, I would need a 2.6 module.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


classes and __init__ question

2010-05-17 Thread Alex Hall
Hi all,
I am a bit confused about classes. What do you pass a class, since all
the actual information is passed to __init__? For example, say you
have a dog class. The dog object has a name, a size, and a color. I
believe you would say this:

class dog():
 def __init__(self, name, size, color):
  self.name=name
  self.size=size
  self.color=color
 #end def
#end class

What, then, gets passed to the class constructor?
class dog(whatGoesHere?):
Sometimes I see things passed to this. For example, if you create a
class for a wxPython frame, you will say:
class myapp(wx.App):
In this case you pass something. However, I have a class that I use in
one of my programs to create "contact" objects, which looks like this:
class contact():
 def __init__(self, name, email, status, service):
  self.name=name
  self.email=email
  self.status=status
  self.service=service
 #end def
#end class

Here, I do not pass anything to the class, only to __init__. What is going on?

On a related note, is it horrible for resource usage to create a large
array, up to 500 or so, where each member is a small object? I am
thinking of, for example, a game board array where each member of the
array is a "square" object. A square might have a status, a color, and
other flags associated with it, so you could then say something like
board[i][j].hasGamePiece=True. Lookups and adjustments like this will
be going on a lot. Am I better off using an array of numbers where
each number means something different?

Thanks in advance for any info.


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classes and __init__ question

2010-05-17 Thread Alex Hall
On 5/17/10, Patrick Maupin  wrote:
> On May 17, 3:19 pm, Alex Hall  wrote:
>> Hi all,
>> I am a bit confused about classes. What do you pass a class, since all
>> the actual information is passed to __init__? For example, say you
>> have a dog class. The dog object has a name, a size, and a color. I
>> believe you would say this:
>>
>> class dog():
>>  def __init__(self, name, size, color):
>>   self.name=name
>>   self.size=size
>>   self.color=color
>>  #end def
>> #end class
>>
>> What, then, gets passed to the class constructor?
>> class dog(whatGoesHere?):
>> Sometimes I see things passed to this. For example, if you create a
>> class for a wxPython frame, you will say:
>> class myapp(wx.App):
>> In this case you pass something. However, I have a class that I use in
>> one of my programs to create "contact" objects, which looks like this:
>> class contact():
>>  def __init__(self, name, email, status, service):
>>   self.name=name
>>   self.email=email
>>   self.status=status
>>   self.service=service
>>  #end def
>> #end class
>>
>> Here, I do not pass anything to the class, only to __init__. What is going
>> on?
>>
>> On a related note, is it horrible for resource usage to create a large
>> array, up to 500 or so, where each member is a small object? I am
>> thinking of, for example, a game board array where each member of the
>> array is a "square" object. A square might have a status, a color, and
>> other flags associated with it, so you could then say something like
>> board[i][j].hasGamePiece=True. Lookups and adjustments like this will
>> be going on a lot. Am I better off using an array of numbers where
>> each number means something different?
>>
>> Thanks in advance for any info.
>>
>> --
>> Have a great day,
>> Alex (msg sent from GMail website)
>> mehg...@gmail.com;http://www.facebook.com/mehgcap
>
> What you are calling "passing to a class" is the superclass (or list
> of superclasses) if you are creating a subclass.
So what is a subclass compared to a class? Are you saying that what is
passed to the class, so what is in the parentheses of the class, is
really the superclass? If so, what is the advantage of doing this; why
not just create a class that is not a sub? I thinking I am missing
something elementary here. :)
>
> Under Python 2.x, you might want to subclass object (if you need/want
> a newstyle class), so it is fairly common to see:
>
> class foo(object):
>whatever
In Java, a class is an object. Is Python the same thing? Would you say
that my dog class, for example, creates a new dog object when an
instance is instantiated?
Thanks.
>
> Regards,
> Pat
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


another question about classes and subclassing

2010-05-18 Thread Alex Hall
Hi again all,
More about classes. I am still looking into my battleship game, and I
will have several different craft. All craft have common attribs
(position, alive, and so on) but each craft may be a surface ship,
submarine, or airplane. All three are craft, but a submarine can be
submerged or not, which does not apply to a surface ship or a plane,
while a plane can be airborne or not, which is not applicable to the
other two. Is there any advantage to creating a craft class:

class craft():
 #has attribs common to any and all craft
#end class

then doing something like:

class submarine(craft):
 #sub-specific attribs
#end class

How would I create a submarine, and then get at the craft-level
attribs? Come to think of it, how would I pass anything to the craft
constructor (position and alive, for example) when creating a new
submarine object? Am I even doing this right to make submarine a
subclass of craft? Thanks.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: another question about classes and subclassing

2010-05-18 Thread Alex Hall
Okay, that makes sense. So by calling submarine(craft) I am bringing
in all of craft's attribs (subclassing)? Or does calling craft's
__init__ method do that instead? Is there an advantage to doing it
this way, rather than just making separate classes for everything,
except for my own sense of organization; speed, memory usage, less
coding? Thanks.

On 5/18/10, Dave Angel  wrote:
> Alex Hall wrote:
>> Hi again all,
>> More about classes. I am still looking into my battleship game, and I
>> will have several different craft. All craft have common attribs
>> (position, alive, and so on) but each craft may be a surface ship,
>> submarine, or airplane. All three are craft, but a submarine can be
>> submerged or not, which does not apply to a surface ship or a plane,
>> while a plane can be airborne or not, which is not applicable to the
>> other two. Is there any advantage to creating a craft class:
>>
>> class craft():
>>  #has attribs common to any and all craft
>> #end class
>>
>> then doing something like:
>>
>> class submarine(craft):
>>  #sub-specific attribs
>> #end class
>>
>> How would I create a submarine, and then get at the craft-level
>> attribs? Come to think of it, how would I pass anything to the craft
>> constructor (position and alive, for example) when creating a new
>> submarine object? Am I even doing this right to make submarine a
>> subclass of craft? Thanks.
>>
>>
> Inside the __init__() method of Submarine, simply call the __init__()
> method of Craft, with appropriate parameters.
>
> As for getting at the attributes of the Craft parent class, from a
> Submarine object, you simply reference the attributes as always.  If
> they're not overridden in Submarine, they'll be searched for in Craft.
>
>
> DaveA
>
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: another question about classes and subclassing

2010-05-18 Thread Alex Hall
On 5/18/10, Dave Angel  wrote:
> Alex Hall wrote:
>> Okay, that makes sense. So by calling submarine(craft) I am bringing
>> in all of craft's attribs (subclassing)? Or does calling craft's
>> __init__ method do that instead? Is there an advantage to doing it
>> this way, rather than just making separate classes for everything,
>> except for my own sense of organization; speed, memory usage, less
>> coding? Thanks.
>>
>> 
>>>
> You put your response at the wrong end of the message.  It should
> *follow* whatever you're quoting.  So in your case, I'm forced to delete
> everything just to make the order correct.
Sorry, top-posting is a habit on some other lists I am on, and
sometimes it follows me to lists where in-line posting is the way to
do it.
>
> You don't call Submarine(Craft), as it's not a function.  That's a class
> definition. You instantiate a Submarine by something like:
>
> sub = Submarine(arg1, arg2, arg3)
>
> And those three arguments are then passed to the __init__() method of
> Submarine.  It may choose to call the __init__() method of Craft, in the
> method.
So that is the only way of making submarine inherit craft, by calling
craft's __init__ inside submarine's __init__. Okay, I think I get it.
>
> There are lots of advantages of using inheritance.  First, any common
> code only has to be entered once, so you'll only have to fix it once
> when you find mistakes, or decide to redesign.
Very true.
> Second, it's easier to
> read - very important.  It may take less memory, but probably not.  And
> it's not likely to have any speed impact.
>
> Craft instances don't have any instance data attributes if nobody
> assigns them.  And that's normally the job of __init__().  So naturally,
> you need to call it from the Submarine class.
Right, I think I have it now... At least I hope I do!
>
> Incidentally, convention is to capitalize class names.
Yes, I had planned on doing that in my project, but I got caught up in
just making it work and forgot to do so. Thanks for the reminder.
>
> DaveA
>
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


optional argument to a subclass of a class

2010-05-20 Thread Alex Hall
Hi all,
I am now trying to allow my classes, all of which subclass a single
class (if that is the term), to provide optional arguments. Here is
some of my code:

class Craft():
 def __init__(self,
 name,
 isAircraft=False,
 id=helpers.id(),
 hits=0,
 weapons=[]):
  self.name=name
  self.id=id
  self.hits=hits
  self.weapons=weapons
  self.isAircraft=isAircraft
 #end def
#end class


#now a class for each type of craft in the game
#each will subclass the Craft class, but each also has its own settings

class Battleship(Craft):
 def __init__(self,
 name,
 maxHits):
  Craft.__init__(self, name)
  self.maxHits=maxHits
  self.length=maxHits #in Battleship, each ship's length is the same
as how many times it can be hit
 #end def
#end class


I want to be able to say something like
b=Battleship("battleship1", 4, weapons=["missile1","missile2"])
When I do that, though, I get a traceback on the above line saying
"type error: __init__() got an unexpected keyword argument 'weapons'".
What did I do wrong / what do I need to change so that any Craft
(Battleship, Carrier, and so on) can optionally provide a list of
weapons, or any other arguments to which I assign default values in my
Craft class? I hope this makes sense.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: optional argument to a subclass of a class

2010-05-20 Thread Alex Hall
On 5/20/10, Patrick Maupin  wrote:
> On May 20, 9:56 pm, Alex Hall  wrote:
>> Hi all,
>> I am now trying to allow my classes, all of which subclass a single
>> class (if that is the term), to provide optional arguments. Here is
>> some of my code:
>>
>> class Craft():
>>  def __init__(self,
>>  name,
>>  isAircraft=False,
>>  id=helpers.id(),
>>  hits=0,
>>  weapons=[]):
>>   self.name=name
>>   self.id=id
>>   self.hits=hits
>>   self.weapons=weapons
>>   self.isAircraft=isAircraft
>>  #end def
>> #end class
>>
>> #now a class for each type of craft in the game
>> #each will subclass the Craft class, but each also has its own settings
>>
>> class Battleship(Craft):
>>  def __init__(self,
>>  name,
>>  maxHits):
>>   Craft.__init__(self, name)
>>   self.maxHits=maxHits
>>   self.length=maxHits #in Battleship, each ship's length is the same
>> as how many times it can be hit
>>  #end def
>> #end class
>>
>> I want to be able to say something like
>> b=Battleship("battleship1", 4, weapons=["missile1","missile2"])
>> When I do that, though, I get a traceback on the above line saying
>> "type error: __init__() got an unexpected keyword argument 'weapons'".
>> What did I do wrong / what do I need to change so that any Craft
>> (Battleship, Carrier, and so on) can optionally provide a list of
>> weapons, or any other arguments to which I assign default values in my
>> Craft class? I hope this makes sense.
>>
>> --
>> Have a great day,
>> Alex (msg sent from GMail website)
>> mehg...@gmail.com;http://www.facebook.com/mehgcap
>
> You overrode the __init__method from the superclass.
I know, I thought I had to in order to make all of Craft's attribs
available to the Battleship. Is that not the case?
>
> One thing you can do is in battleship, you can accept additional
> keyword arguments:
>
> def __init__(self, name, ..., **kw):
>
> Then you could invoke the superclass's init:
>
> Craft.__init__(self, name, **kw)
So how do I get at anything inside **kw? Is it a list?
>
> Regards,
> Pat
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: optional argument to a subclass of a class

2010-05-20 Thread Alex Hall
On 5/20/10, alex23  wrote:
> Patrick Maupin  wrote:
>> One thing you can do is in battleship, you can accept additional
>> keyword arguments:
>>
>> def __init__(self, name, ..., **kw):
>>
>> Then you could invoke the superclass's init:
>>
>> Craft.__init__(self, name, **kw)
>
> _All_ of which is covered in the tutorial. At what point do we expect
> people to actually put some effort into learning the language
> themselves? Is this why we're constantly spammed with "write my code
> for me" requests?
I am certainly NOT asking anyone to write my code for me. In fact, I
almost never copy and paste code, since writing it myself helps me to
both remember it and examine it to see what is going on and figure out
why it works. I am basically teaching myself Python; my experience is
in Java (basic), JS (somewhat advanced), and a smattering of other
languages. I have rarely dealt with classes before, and certainly not
sub-classing. I have googled all of this and have read the docs and
tutorials, but nothing made sense enough for me to figure out why I
would be getting my particular error. I have since updated each ship's
__init__ to accept all the arguments that Craft accepts so that I can
support all optional arguments, but I thought subclassing was supposed
to take care of this for me... Suppose not.
>
> If you're asking _basic_ "how do I" questions, and you don't even have
> the common sense to read through the support docs before doing so,
> then you really should be directing questions here:
> http://mail.python.org/mailman/listinfo/tutor
Again, I have read the docs. I often find them quite useful, but there
are times where a new concept, in a relatively new language, just will
not work and a doc is not going to say "at this point in your code,
you should to A instead of B, because..."
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: optional argument to a subclass of a class

2010-05-21 Thread Alex Hall
On 5/21/10, Peter Otten <__pete...@web.de> wrote:
> Alex Hall wrote:
>
>> Hi all,
>> I am now trying to allow my classes, all of which subclass a single
>> class (if that is the term), to provide optional arguments. Here is
>> some of my code:
>>
>> class Craft():
>>  def __init__(self,
>>  name,
>>  isAircraft=False,
>>  id=helpers.id(),
>>  hits=0,
>>  weapons=[]):
>>   self.name=name
>>   self.id=id
>>   self.hits=hits
>>   self.weapons=weapons
>>   self.isAircraft=isAircraft
>>  #end def
>> #end class
>>
>>
>> #now a class for each type of craft in the game
>> #each will subclass the Craft class, but each also has its own settings
>>
>> class Battleship(Craft):
>>  def __init__(self,
>>  name,
>>  maxHits):
>>   Craft.__init__(self, name)
>>   self.maxHits=maxHits
>>   self.length=maxHits #in Battleship, each ship's length is the same
>> as how many times it can be hit
>>  #end def
>> #end class
>>
>>
>> I want to be able to say something like
>> b=Battleship("battleship1", 4, weapons=["missile1","missile2"])
>> When I do that, though, I get a traceback on the above line saying
>> "type error: __init__() got an unexpected keyword argument 'weapons'".
>> What did I do wrong / what do I need to change so that any Craft
>> (Battleship, Carrier, and so on) can optionally provide a list of
>> weapons, or any other arguments to which I assign default values in my
>> Craft class? I hope this makes sense.
>
> You have to repeat the arguments for the base class in the Battleship
> initializer. Battleship(...) will only invoke Battleship.__init__(...), not
> Craft.__init__(...) -- so you have to do that explicitly inside
> Battleship.__init__() while passing along all parameters it is supposed to
> process. As simplified example:
>
> class Craft(object):
> def __init__(self, name, id=None, weapons=None):
> if id is None:
> id = helpers.id()
> if weapons is None:
> weapons = []
> self.name = name
> self.id = id
> self.weapons = weapons
>
> class Battleship(Craft):
> def __init__(self, name, id=None, weapons=None, max_hits=None):
> Craft.__init__(self, name, id, weapons)
> self.max_hits = max_hits
>
> Notice how using None to signal that a value was not provided simplifies
> things; without it you'd have to put a meanigful default for weapons into
> both the Craft and Battleship class. If you want a unique id for every Craft
> providing helpers.id() as a default is just wrong; default arguments are
> calculated once and you would end up with the same id for every Craft
> instance.
Yes, I found that out the hard way :), but it made perfect sense as
soon as I realized that I was not getting unique IDs; the class()
statement is just a fancy function call in Python, as I understand it,
so of course it would be called only once, not each time I make a new
instance.
>
> Peter
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: optional argument to a subclass of a class

2010-05-21 Thread Alex Hall
On 5/21/10, Terry Reedy  wrote:
> On 5/20/2010 10:56 PM, Alex Hall wrote:
>
> A couple of style comments for you to consider.
>
>> class Craft():
>>   def __init__(self,
>>   name,
>>   isAircraft=False,
>>   id=helpers.id(),
>>   hits=0,
>>   weapons=[]):
>
> Not indenting lines after def makes the code harder to read for me, and,
> I expect, many others here who use indentation as a cue. If you want one
> param per line, give them extra indents if you want.
Good point, I had not considered that; Python's relyance on
indentation made me think that indenting past the level of the class
would cause problems.
>
>>self.name=name
>>self.id=id
>>self.hits=hits
>>self.weapons=weapons
>>self.isAircraft=isAircraft
>>   #end def
>> #end class
>
> #end markers are fine for private code but are distracting noise to me,
> and, I expect, other experienced Python coders.
I will try to remember to remove them for posting, but I find them
immensely helpful; using a screen reader, and so not being able to
look at code and see the indentation, means that I have to have a way
to tell myself where things end, much like braces in other languages.
When I post here I will try to remove them, but for code I zip and put
on my website they have to stay since I rely on them and the zip is
just what I am working on at the time, plus there are a lot of those
comments to remove from an entire project.
>
> Terry Jan Reedy
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: optional argument to a subclass of a class

2010-05-21 Thread Alex Hall
On 5/21/10, Christian Heimes  wrote:
> Am 21.05.2010 04:56, schrieb Alex Hall:
>> Hi all,
>> I am now trying to allow my classes, all of which subclass a single
>> class (if that is the term), to provide optional arguments. Here is
>> some of my code:
>>
>> class Craft():
>>   def __init__(self,
>>   name,
>>   isAircraft=False,
>>   id=helpers.id(),
>>   hits=0,
>>   weapons=[]):
>
> I hope you are aware that helpers.id() is called just once when the
> *class* is defined and that the list weapons is shared across all
> instances of the craft class. :)
I know id is called once, but what do you mean weapons is shared?
>
> Have you read about *args and **kwargs in the Python docs? I bet you
> find them useful for your problem.
>
> Christian
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: optional argument to a subclass of a class

2010-05-21 Thread Alex Hall
On 5/21/10, Ethan Furman  wrote:
> Alex Hall wrote:
>> On 5/20/10, alex23  wrote:
>> I have since updated each ship's
>> __init__ to accept all the arguments that Craft accepts so that I can
>> support all optional arguments,
>
> Ick.  Now you'll have to change several things if you make one change to
> the Craft class.  Better to do it this way:
>
> [borrowing Peter's example]
>
> class Craft(object):
Curious: I do not pass Craft this "object" keyword and I have no
problems. What is it for? Just a convention, something like self being
called self?
>  def __init__(self, name, id=None, weapons=None):
>  if id is None:
>  id = helpers.id()
>  if weapons is None:
>  weapons = []
>  self.name = name
>  self.id = id
>  self.weapons = weapons
>
> class Battleship(Craft):
>  def __init__(self, name, max_hits=None, **kwds):
>  Craft.__init__(self, name, **kwds)
>  self.max_hits = max_hits
>
>
>
> Notice the **kwds in Battleships's init, both in the parameter line, and
> in the call to Craft's init.  This way all keyword arguments that
> Battleship doesn't directly support will be passed through to Craft.

Thanks, the **kwords makes sense!! I implemented it much as you
described, and life is much easier; each ship or aircraft now has a
simple constructor, and I am still free to change any attrib I want
later or at creation time. A very powerful concept, and I now have
2-line constructors.

class Battleship(Craft):
 def __init__(self, name, **kwords):
  Craft.__init__(self, name, maxHits=4, **kwords) #call the
superclass's __init__

class Carrier(Craft):
 def __init__(self, name, **kwords):
  Craft.__init__(self, name, maxHits=5, **kwords) #call the
superclass's __init__


>
> ~Ethan~
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: optional argument to a subclass of a class

2010-05-21 Thread Alex Hall
On 5/21/10, Chris Rebert  wrote:
> On Fri, May 21, 2010 at 1:09 PM, Alex Hall  wrote:
>> On 5/21/10, Ethan Furman  wrote:
>>> Alex Hall wrote:
>>>> On 5/20/10, alex23  wrote:
>>>> I have since updated each ship's
>>>> __init__ to accept all the arguments that Craft accepts so that I can
>>>> support all optional arguments,
>>>
>>> Ick.  Now you'll have to change several things if you make one change to
>>> the Craft class.  Better to do it this way:
>>>
>>> [borrowing Peter's example]
>>>
>>> class Craft(object):
>> Curious: I do not pass Craft this "object" keyword and I have no
>> problems. What is it for? Just a convention, something like self being
>> called self?
>
> It causes the class to be "new-style". See
> http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes
Oh, I see. Thanks.
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help (I can't think of a better title)

2010-05-22 Thread Alex Hall
On 5/22/10, MRAB  wrote:
> Lanny wrote:
>> The answer may be right infront of me but I really can't figure this
>> out.
>> I'm trying to build a interactive fiction kind of game, silly I know
>> but I
>> am a fan of the genre. I'm trying to build up an index of all the
>> rooms in
>> the game from an outside file called roomlist.txt. The only problem is
>> that
>> every room ends up having four exits. Here's the code.
>>
>>
>> class room() :
>> room_id = 'room_id'
>> name = 'room'
>> description = 'description'
>> item_list =
>> exits = {}
>  > visits = 0
>
> These attributes are being defined as belonging to the class, so they
> will be shared by all the instances of the class. This isn't a problem
> for immutable items such as strings, but is for mutable items such as
> dicts. In short, all the rooms share the same 'exits' dict.
>
> You should really define the instance attributes (variables) in the
> '__init__' method.

I just ran into something similar to this in my Battleship game. I had
a Craft class, which defined attributes for any craft (a recon plane,
a submarine, a battleship, and so on). One such attribute was a
weapons list, much like your exits dictionary; I would assign a couple
weapons to a battleship, but suddenly all my ships and airplanes had
those same weapons. What the great people on this list said to do was
something like this:

class Room():
 def __init__(self, exits):
  if exits==None:
   self.exits={}
  else:
   self.exits=exits

In this way, you can create a new Room object with exits,
r=Room(exits_dict)
or you can create a Room with no exits, and add them later:
r2=Room()
r2.exits["exit1"]="doorway"

but the code in the __init__ method, which will get called as soon as
you create a new Room object, ensures that passing an exits dictionary
will set that instance's exits to what was passed in, while passing
nothing will create a room with an empty dictionary (the if
statement). I hope this made some sense!
>
>> def leave(self, direction)
>> global roomlist
>> global player_current_room
>> if direction not in player_current_room.exitskeys() :
>> print 'There is no exit in that direction.'
>> return 1
>> roomlist[self.room_id] = self
>> player_current_room =
>> roomlist[player_current_room.exits[direction]]
>> print player_current_room.name
>> if player_current_room.visits < 1 :
>> print player_current_room.description
>> if player_current_room.item_list != [] :
>> stdout.write('You can see ')
>> for item in player_current_room.item_list :
>> stdout.write('a')
>> if item.display_name[0] in ['a','e','i','o','u'] :
>>  stdout.write('n ' + item.display_name
>> +
>> ',')
>> else :
>> stdout.write(item.display_name + ',')
>> pass
>>
>> print
>> print 'Exits:',
>> for way in player_current_room.exits :
>> print way.capitalize(),
>> print
>> player_current_room.visits += 1
>> pass
>> else :
>> player_current_room.visits += 1
>> pass
>> pass
>>
>> def build_rooms(room_file) :
>> global roomlist
>> rfile = open(room_file)
>> tmp_builder = ''
>> for line in rfile :
>> tmp_builder = tmp_builder + line[:-1]
>> pass
>> for location in tmp_builder.rsplit('::') :
>> if location.rsplit(';')[-1] == '' :
>> location = location[:-1]
>> if len(location.rsplit(';')) != 5 :
>> if '-dev' or '-v' in argv :
>> print location.rsplit(';')[0], 'had',
>> len(location.rsplit(';')), 'values in it, 5 expected'
>> for value in location.rsplit(';') :
>> print; print value
>> foobar.append(value)
>> print 'A room failed to initalize due to either too
>> much or
>> not enough values being present in the build file'
>> pass
>> pass
>> else :
>> roomlist[location.rsplit(';')[0]] = room()
>> roomlist[location.rsplit(';')[0]].room_id =
>> location.rsplit(';')[0]
>> roomlist[location.rsplit(';')[0]].name =
>> location.rsplit(';')[1]
>> roomlist[location.rsplit(';')[0]].description =
>> location.rsplit(';')[2]
>> if location.rsplit(';')[3] != 'none' :
>> pass
>> tmp_var = location.rsplit(';')[4]
>> print location.rsplit(';')[0],
>> roomlist[location.rsplit(';')[0]].exits, 'before'
>> for way in tmp_var.rsplit(',') :
>> roomlist[location.rsplit(';')[0]].exits[way.rsplit(':')
>> [0]]
>> = way.rsplit(':')[1]
>>
>> roomlist = {}
>> build_rooms('room_list.txt')
>>
>> And here is 

Re: General questions - where & how

2010-06-04 Thread Alex Hall
I am not sure about a search feature for the archives, but I can tell
you about a "tutor" list for those new and somewhat new to Python
(like me). Of course, both that list and this one are excellent
resources, but the tutor list seems to be for questions generally
encountered by relatively new Python programmers. Just FYI.

On 6/4/10, Uriah Eisenstein  wrote:
> Hi all,
> I'm relatively new to Python and have a few questions. Frankly, it took me a
> while to find on python.org what seems like a suitable place to post my
> questions. However, I'd like to check the archives and see if they haven't
> been discussed already... But I don't find a Search function. Is there such
> a thing?
>
> TIA,
> Uriah
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a +b ?

2010-06-11 Thread Alex Hall
On 6/11/10, yanhua  wrote:
> hi,all!
> it's a simple question:
> input two integers A and B in a line,output A+B?
>
> this is my program:
> s = input()
> t = s.split()
> a = int(t[0])
> b = int(t[1])
> print(a+b)
>
> but i think it's too complex,can anybody tell to slove it with less code.
Just a thought, but less code is not always better; more code and
comments often help others, and even yourself if you return to a
project after some time, understand what the code does and how it
works. However, you could try this:
t=input().split()
print(str(int(t[0])+int(t[1])))
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IOError and Try Again to loop the loop.

2010-07-11 Thread Alex Hall
It seems like seeing the code, or at least the bit in question, would
be easier, but what about:

for img in range(0, len(imagesToUpload:))
 try:
  #do the thumbnail / upload thing on images[i]
 exceptIOError:
  i=0

This will duplicate a lot of the images already processed, but you
said you are just restarting the script anyway. If you are in a while
loop, just move the processing to the for loop and use the while to
add all images to be processed to a list.

On 7/11/10, The Danny Bos  wrote:
> Heya,
>
> I'm running a py script that simply grabs an image, creates a
> thumbnail and uploads it to s3. I'm simply logging into ssh and
> running the script through Terminal. It works fine, but gives me an
> IOError every now and then.
>
> I was wondering if I can catch this error and just get the script to
> start again?
> I mean, in Terminal it dies anyway, so I have to start it again by
> hand, which is a pain as it dies so sporadically. Can I automate this
> error, catch it and just get it to restart the loop?
>
> Thanks for your time and energy,
>
> Danny
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Contains/equals

2010-08-19 Thread Alex Hall
On 8/19/10, Peter Otten <__pete...@web.de> wrote:
> Karsten Wutzke wrote:
>
>> I have an object which has a list of other complex objects. How do I
>> best achieve a complex "contains" comparison based on the object's
>> class? In Java terms, I'm looking for an equivalent to equals(Object)
>> in Python. Does a similar thing exist? Directions appreciated.
>
> I can't infer from your question whether you already know about
> __contains__(). So there:
>
 class Cornucopia:
> ... def __contains__(self, other):
> ... return True
> ...
 c = Cornucopia()
 42 in c
> True
 "cherry pie" in c
> True
 c in c
> True
You may also want to use the double equals operator; in Java, one
thing I wish I could do is
String s="abc";
String t="def";
if(s==t)...
In Python, as I understand it, you can define this behavior.

class c(object):
 def __init__(self, a=1, b=2):
  self.a=a; self.b=b

 def __eq__(self, obj):
  if self.a==obj.a and self.b==obj.b: return True
  return False


You can now say:
obj1=c()
obj2=c()
print(obj1==obj2) #prints True
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Global hoykey on windows

2010-10-05 Thread Alex Hall
On 10/5/10, Sebastian Alonso  wrote:
> Hey everyone, I've been working on an app that uses global hotkey and
> it's a very important part of the app, so far I have been using
> python-keybinder [0] and it's been working great on linux, but now I want to
> make it work under windows and there was no way to make it work. Any other
> library I should try out? Any advice/trick you know to achieve this?
When I was doing this, I found the below website to solve my problem,
and I still use the system described on said site.
http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkeys.html
>
> thanks in advance
>
> seba
>
> [0] http://kaizer.se/wiki/keybinder/
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythagorean triples exercise

2010-10-21 Thread Alex Hall
On 10/21/10, Baba  wrote:
> Hi everyone
>
> i need a hint regarding the following exercise question:
>
> "Write a program that generates all Pythagorean triples whose small
> sides are no larger than n.
> Try it with n <= 200."
>
> what is "n" ? i am guessing that it is a way to give a bound to the
> triples to be returned but i can't figure out where to fit in "n".
Picture a right triangle. The two short sides (the two sides coming
off either side of the right angle) must be no longer than n. The
lengths of these two sides are a and b, and you are looping until
either side exceeds n... HTH.
>
> a^a + b^b = c^c is the condition to satisfy and i need to use loops
> and "n" will be an upper limit of one (or more?) of the loops but i am
> a bit lost. Please help me get thinking about this right.
>
> import math
> for b in range(20):
> for a in range(1, b):
> c = math.sqrt( a * a + b * b)
> if c % 1 == 0:
> print (a, b, int(c))
>
> this returns
>
> (3, 4, 5) (6, 8, 10) (5, 12, 13) (9, 12, 15) (8, 15, 17) (12, 16, 20)
>
> is that the desired output? what is the step that i'm missing?
>
> thanks in advance
>
> Baba
> p.s. this is not homework but self-study
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Create a GUI and EXE for a python app?

2010-10-28 Thread Alex Hall
There is tkinter or WX for a gui solution. I use wx just because I
already know it and it does what I need it to do, so I see no reason
to switch to a different library to do the same thing.

On 10/28/10, brad...@hotmail.com  wrote:
> Thanks ill give it a try! Anyone know about the GUI then?
>
> --Original Message--
> From: Chris Rebert
> Sender: ch...@rebertia.com
> To: Braden Faulkner
> Cc: python-list@python.org
> Subject: Re: Create a GUI and EXE for a python app?
> Sent: Oct 28, 2010 5:04 PM
>
> On Thu, Oct 28, 2010 at 1:53 PM, Braden Faulkner 
> wrote:
>> Having trouble with my mail client, so sorry if this goes through more
>> than
>> once.
>> I'm worknig on a simple math program as my first application. I would like
>> to make a cross-platform pretty GUI for it and also package it up in a EXE
>> for distribution on Windows.
>> What are the best and easiest ways I can do this?
>
> For the latter, py2exe:
> http://www.py2exe.org/
>
> Cheers,
> Chris
>
>
>
> Sent wirelessly from my BlackBerry.
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list