Re: Output showing "None" in Terminal

2020-08-27 Thread Py Noob
Thank you so much for the help.

I'm self-studying and watching tutorials on youTube. The problem was given
as an exercise after the tutorial.
I did modify my code based on the suggestions here and it helps.

Thank you!

On Tue, Aug 25, 2020 at 4:31 PM Schachner, Joseph <
joseph.schach...@teledyne.com> wrote:

> The very first line of your function km_mi(): ends it:
> def km_mi():
> return answer
>
> answer has not been assigned, so it returns None.
>
> Advice: remove that "return" line from there.  Also get rid of the last
> line, answer = km_mi which makes answer refer to the function km_mi().
> Put the "return answer" line at the end, where the "answer=km_mi" used to
> be.
>
> That should help.  The code calculates "answer".   It prints "answer".
>  You should return "answer" at the end, after it has been calculated.
>
> --- Joseph S.
>
> -Original Message-
> From: Py Noob 
> Sent: Monday, August 24, 2020 9:12 AM
> To: python-list@python.org
> Subject: Output showing "None" in Terminal
>
> Hi!
>
> i'm new to python and would like some help with something i was working on
> from a tutorial. I'm using VScode with 3.7.0 version on Windows 7. Below is
> my code and the terminal is showing the word "None" everytime I execute my
> code.
>
> Many thanks!
>
> print("Conversion")
>
> def km_mi():
> return answer
>
> selection = input("Type mi for miles or km for kilometers: ")
>
> if selection == "mi":
> n = int(input(print("Please enter distance in miles: ")))
> answer = (1.6*n)
> print("%.2f" % answer, "miles")
>
> else:
> n = float(input(print("Please enter distance in kilometers: ")))
> answer = (n/1.6)
> print("%.2f" % answer, "kilometers")
>
> answer = km_mi
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Output showing "None" in Terminal

2020-08-24 Thread Py Noob
Thank you for the clarification.
What I'm trying to achieve here are:

User be able to choose miles or kilometers to convert.
When selected (mi/km), prints out the user input and the answer.
km to mi = km/1.609
mi to km = mi*1.609

Thank you again!


On Mon, Aug 24, 2020 at 1:41 PM Calvin Spealman  wrote:

> How are you actually running your code?
>
> "None" is the default return value of all functions in Python. But, the
> interpreter is supposed to suppress it as a displayed result.
>
> As a side note, both your km_mi() function and the line "answer = km_mi"
> are certainly wrong, but it is not clear what you intend to do.
>
> On Mon, Aug 24, 2020 at 4:25 PM Py Noob  wrote:
>
>> Hi!
>>
>> i'm new to python and would like some help with something i was working on
>> from a tutorial. I'm using VScode with 3.7.0 version on Windows 7. Below
>> is
>> my code and the terminal is showing the word "None" everytime I execute my
>> code.
>>
>> Many thanks!
>>
>> print("Conversion")
>>
>> def km_mi():
>> return answer
>>
>> selection = input("Type mi for miles or km for kilometers: ")
>>
>> if selection == "mi":
>> n = int(input(print("Please enter distance in miles: ")))
>> answer = (1.6*n)
>> print("%.2f" % answer, "miles")
>>
>> else:
>> n = float(input(print("Please enter distance in kilometers: ")))
>> answer = (n/1.6)
>> print("%.2f" % answer, "kilometers")
>>
>> answer = km_mi
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>>
>
> --
>
> CALVIN SPEALMAN
>
> SENIOR QUALITY ENGINEER
>
> cspea...@redhat.com  M: +1.336.210.5107
> [image: https://red.ht/sig] <https://red.ht/sig>
> TRIED. TESTED. TRUSTED. <https://redhat.com/trusted>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Output showing "None" in Terminal

2020-08-24 Thread Py Noob
Hi!

i'm new to python and would like some help with something i was working on
from a tutorial. I'm using VScode with 3.7.0 version on Windows 7. Below is
my code and the terminal is showing the word "None" everytime I execute my
code.

Many thanks!

print("Conversion")

def km_mi():
return answer

selection = input("Type mi for miles or km for kilometers: ")

if selection == "mi":
n = int(input(print("Please enter distance in miles: ")))
answer = (1.6*n)
print("%.2f" % answer, "miles")

else:
n = float(input(print("Please enter distance in kilometers: ")))
answer = (n/1.6)
print("%.2f" % answer, "kilometers")

answer = km_mi
-- 
https://mail.python.org/mailman/listinfo/python-list


Detect dotted (broken) lines only in an image using OpenCV

2020-04-15 Thread Edu Py
I am trying to learn techniques on image feature detection.

I have managed to detect horizontal line(unbroken/continuous), however I am 
having trouble detecting all the dotted/broken lines in an image.

Here is my test image, as you can see there are dotted lines and some 
text/boxes etc.


my code is below:

import cv2
import numpy as np

img=cv2.imread('test.jpg')
img=functions.image_resize(img,1000,1000) #function from a script to resize 
image to fit my screen
imgGray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
imgEdges=cv2.Canny(imgGray,100,250)
imgLines= cv2.HoughLinesP(imgEdges,2,np.pi/100,60, minLineLength = 10, 
maxLineGap = 100)
for x1,y1,x2,y2 in imgLines[0]:
cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)

cv2.imshow('Final Image with dotted Lines detected',img) 

My output image is below. As you can see I only managed to detect the last 
dotted line. I have played around with the parameters rho,theta,min/max line 
but no luck.

Any advice is greatly appreciated :)

For the original link - which has the images 
https://stackoverflow.com/questions/61239652/detect-dotted-broken-lines-only-in-an-image-using-opencv
-- 
https://mail.python.org/mailman/listinfo/python-list


exec and traceback

2018-01-22 Thread ken . py



I'm using exec() to run a (multi-line) string of python code. If an  
exception occurs, I get a traceback containing a stack frame for the  
string. I've labeled the code object with a "file name" so I can  
identify it easily, and when I debug, I find that I can interact with  
the context of that stack frame, which is pretty handy.


What I would like to also be able to do is make the code string  
visible to the debugger so I can look at and step through the code in  
the string as if it were from a python file.


Lest this topic forks into a security discussion, I'll just add that  
for my purposes the data source is trusted. If you really want to talk  
about the security of using exec and eval, fine, but start another  
thread (BTW, I've written a simple secure eval())


Thanks in advance,
Ken



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


dictionary total sum

2016-09-07 Thread py

Hello,

any ideas why this does not work?


def add(key, num):

... a[key] += num
...

a={}
a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22)
a

{'007-12': 22} # OK here, this is what I want

a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22)
a

{'007-12': None} # why does this became None?

Thanks

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


Behaviour of list comprehensions

2016-02-02 Thread arsh . py
I am having some understandable behaviour from one of my function name 
week_graph_data() which call two functions those return a big tuple of tuples, 
But in function week_graph_data() line no. 30 does not work(returns no result 
in graph or error). 

I have check both functions are called in week_graph_data() individually and 
those run perfectly. (returning tuple of tuples)

here is my code: pastebin.com/ck1uNu0U
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Begginer in python trying to load a .dll

2014-08-13 Thread c1234 py
Thanks a lot. 



El martes, 12 de agosto de 2014 17:17:26 UTC-3, Mark Lawrence  escribió:
> On 12/08/2014 20:25, c1234 py wrote:
> 
> > El martes, 12 de agosto de 2014 16:16:21 UTC-3, Christian Gollwitzer  
> > escribi�:
> 
> >> Am 12.08.14 20:36, schrieb c1223:
> 
> >>
> 
> >>> Hi, Im working in the development of a program based in python that
> 
> >>
> 
> >>> allow us to contrl a spectometer. The spectometer has an .dll file.
> 
> >>
> 
> >>> The idea is to work through this dll and operate the spectometer. The
> 
> >>
> 
> >>> name of the .dll is AS5216.dll. I've trying with ctype, but it
> 
> >>
> 
> >>> doesn't work. I'm begginer in python. All the comments are useful to
> 
> >>
> 
> >>> me.
> 
> >>
> 
> >>
> 
> >>
> 
> >> For sure this DLL will come with a header file for C. You could pass it
> 
> >>
> 
> >> through SWIG and see if it generates a useful Python module. You need a
> 
> >>
> 
> >> C compiler for that route, though.
> 
> >>
> 
> >>
> 
> >>
> 
> >>Christian
> 
> >
> 
> >
> 
> > How can i pass it through a SWIG?, i don't know that and what it mean?
> 
> >
> 
> 
> 
> Start here http://www.swig.org/ which you could easily have found for 
> 
> yourself, as I did by using a search engine.
> 
> 
> 
> Also would you please access this list via 
> 
> https://mail.python.org/mailman/listinfo/python-list or read and action 
> 
> this https://wiki.python.org/moin/GoogleGroupsPython to prevent us
> 
> seeing double line spacing and single line paragraphs, thanks.
> 
> 
> 
> -- 
> 
> My fellow Pythonistas, ask not what our language can do for you, ask
> 
> what you can do for our language.
> 
> 
> 
> Mark Lawrence

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


Re: Begginer in python trying to load a .dll

2014-08-12 Thread c1234 py
El martes, 12 de agosto de 2014 16:16:21 UTC-3, Christian Gollwitzer  escribió:
> Am 12.08.14 20:36, schrieb c1223:
> 
> > Hi, Im working in the development of a program based in python that
> 
> > allow us to contrl a spectometer. The spectometer has an .dll file.
> 
> > The idea is to work through this dll and operate the spectometer. The
> 
> > name of the .dll is AS5216.dll. I've trying with ctype, but it
> 
> > doesn't work. I'm begginer in python. All the comments are useful to
> 
> > me.
> 
> 
> 
> For sure this DLL will come with a header file for C. You could pass it 
> 
> through SWIG and see if it generates a useful Python module. You need a 
> 
> C compiler for that route, though.
> 
> 
> 
>   Christian


How can i pass it through a SWIG?, i don't know that and what it mean?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Begginer in python trying to load a .dll

2014-08-12 Thread c1234 py
On Tuesday, August 12, 2014 4:09:13 PM UTC-3, Chris Angelico wrote:
> On Wed, Aug 13, 2014 at 4:58 AM, Rob Gaddi
> 
>  wrote:
> 
> > Great.  And that fails in what way, on which line, with what error message?
> 
> 
> 
> And, is that the entire program? Because if it is, then I can see at
> 
> least one problem, a NameError.
> 
> 
> 
> ChrisA

This appear in the terminal:


>>> runfile('C://Python Scripts')
  File "C:\\sitecustomize.py", line 585, in runfile
execfile(filename, namespace)
  File "C://Sin título 38.py", line 19, in 
hllApi = hllApiProto (("HLLAPI", hllDll), hllApiParams)
AttributeError: function 'HLLAPI' not found
>>> Traceback (most recent call last):
  File "", line 1, in 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Begginer in python trying to load a .dll

2014-08-12 Thread c1234 py
On Tuesday, August 12, 2014 3:36:17 PM UTC-3, c1234 py wrote:
> Hi, 
> 
> Im working in the development of a program based in python that allow us to 
> contrl a spectometer. The spectometer has an .dll file. The idea is to work 
> through this dll and operate the spectometer. 
> 
> The name of the .dll is AS5216.dll. I've trying with ctype, but it doesn't 
> work. 
> 
> I'm begginer in python. 
> 
> All the comments are useful to me.


I'm using this


>>import ctypes
hllDll=ctypes.WinDLL("C:\\AS5216.dll")


hllApiProto = ctypes.WINFUNCTYPE (ctypes.c_int,ctypes.c_void_p,
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p)
hllApiParams = (1, "p1", 0), (1, "p2", 0), (1, "p3",0), (1, "p4",0),


hllApi = hllApiProto (("HLLAPI", hllDll), hllApiParams)

p1 = ctypes.c_int (1)
p2 = ctypes.c_char_p (sessionVar)
p3 = ctypes.c_int (1)
p4 = ctypes.c_int (0)
hllApi (ctypes.byref (p1), p2, ctypes.byref (p3), ctypes.byref (p4))



Thanks



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


Re: __pycache__, one more good reason to stck with Python 2?

2011-01-19 Thread H₂0 . py
On Jan 18, 4:04 am, Peter Otten <__pete...@web.de> wrote:
>
> What's the advantage of 'find ... | xargs ...' over 'find ... -exec ...'?

Portability. Running the '-exec' version will work fine in a directory
with a relatively small number of files, but will fail on a large one.
'xargs', which is designed to handle exactly that situations, splits
the returned output into chunks that can be handled by 'rm' and such.
'|xargs' is always the preferred option when you don't know how large
the output is going to be.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 4 hundred quadrillonth?

2009-05-21 Thread seanm . py
On May 21, 5:36 pm, Christian Heimes  wrote:
> seanm...@gmail.com schrieb:
>
> > The explaination in my introductory Python book is not very
> > satisfying, and I am hoping someone can explain the following to me:
>
>  4 / 5.0
> > 0.80004
>
> > 4 / 5.0 is 0.8. No more, no less. So what's up with that 4 at the end.
> > It bothers me.
>
> Welcome to IEEE 754 floating point land! :)
>
> Christian

Thanks for the link and the welcome. Now onward to Bitwise
Operations

Sean
-- 
http://mail.python.org/mailman/listinfo/python-list


4 hundred quadrillonth?

2009-05-21 Thread seanm . py
The explaination in my introductory Python book is not very
satisfying, and I am hoping someone can explain the following to me:

>>> 4 / 5.0
0.80004

4 / 5.0 is 0.8. No more, no less. So what's up with that 4 at the end.
It bothers me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Most Basic Question Ever - please help

2009-05-04 Thread seanm . py
On May 3, 12:22 am, CM  wrote:
> On May 2, 4:36 pm, seanm...@gmail.com wrote:
>
>
>
> > I am going to try posting here again with more detail to see if I can
> > finally get my first program to work.
>
> > I am working on a MacBook Pro with OS X 10.4.11. I opened a new window
> > in IDLE to create a file. The file had only one line of code and was
> > saved as module1.py. I saved it to Macintosh HD. The one line of code
> > in the file is copied below:
>
> > print 'Hello module world!'
>
> > I closed the file and tried to run it in IDLE and Terminal, but I have
> > had no success. I'll paste my commands and the error messages below
> > (for IDLE, then Terminal). Any help would be very much appreciated. I
> > feel like the marathon just started and I've fallen flat on my face.
> > Thanks.
>
> > IDLE 2.6.2>>> python module1.py
>
> > SyntaxError: invalid syntax
>
> > sean-m-computer:~ seanm$ python
> > Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
> > [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
> > Type "help", "copyright", "credits" or "license" for more information.>>> 
> > python module1.py
>
> >   File "", line 1
> >     python module1.py
> >                  ^
> > SyntaxError: invalid syntax
>
> Sean, also, keep in mind you can use IDLE to run
> your scripts.  After you have saved a script/program,
> there is an option for Run in the menu, and then under
> that, Run Module.  The output of the script will be
> sent to IDLE window indicated as the Python shell.
> You can also just test code directly from within
> that shell, though for multi-line programs, it is
> easier within the composing window.
>
> I suggest you sign up for the Python tutor 
> list:http://mail.python.org/mailman/listinfo/tutor
>
> And you can search through their big archive of
> questions and answers here:http://www.nabble.com/Python---tutor-f2981.html
>
> The tutors there are great and super-helpful, and
> will field any level of question but are particularly
> good for absolute beginners.
>
> Here is a tutorial on using 
> IDLE:http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html
>
> And here is a very good general programming tutorial online
> book, focusing on Python:http://www.freenetpages.co.uk/hp/alan.gauld/
>
> Good luck!
> Che

Thanks Che! The explaination and links are much appreciated. -Sean
--
http://mail.python.org/mailman/listinfo/python-list


Re: Most Basic Question Ever - please help

2009-05-02 Thread seanm . py
On May 2, 6:25 pm, John Machin  wrote:
> On May 3, 7:46 am, Dave Angel  wrote:
>
>
>
> > seanm...@gmail.com wrote:
> > > I am going to try posting here again with more detail to see if I can
> > > finally get my first program to work.
>
> > > I am working on a MacBook Pro with OS X 10.4.11. I opened a new window
> > > in IDLE to create a file. The file had only one line of code and was
> > > saved as module1.py. I saved it to Macintosh HD. The one line of code
> > > in the file is copied below:
>
> > > print 'Hello module world!'
>
> > > I closed the file and tried to run it in IDLE and Terminal, but I have
> > > had no success. I'll paste my commands and the error messages below
> > > (for IDLE, then Terminal). Any help would be very much appreciated. I
> > > feel like the marathon just started and I've fallen flat on my face.
> > > Thanks.
>
> > > IDLE 2.6.2
>
> > >>>> python module1.py
>
> > > SyntaxError: invalid syntax
>
> > > sean-m-computer:~ seanm$ python
> > > Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
> > > [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
> > > Type "help", "copyright", "credits" or "license" for more information.
>
> > >>>> python module1.py
>
> > >   File "", line 1
> > >     python module1.py
> > >                  ^
> > > SyntaxError: invalid syntax
>
> > In both cases, you're already running python.  Why would you expect to
> > have to run python inside python?
>
> > Once you're at a python prompt (in either of your cases), you use the
> > command "import" to load a module.  And you do not put the ".py"
> > extension on the parameter.  Specifically, it should look like this, and
> > very similar for IDLE.
>
> > M:\Programming\Python\sources\temp>c:\ProgFiles\Python26\python.exe
> > Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
> > (Intel)] on
> > win32
> > Type "help", "copyright", "credits" or "license" for more information.
> >  >>> import module1
> > Hello module world!
> >  >>>
>
> Dave, importing modules which have side effects like printing is NOT a
> good habit to which a beginner should be introduced. He needs to know
> how to run a script.
>
> Sean, in Terminal, instead of typing
>     python
> type
>     python module1.py
>
> and I suggest that you give your script (not module) a more meaningful
> name.
>
> HTH,
> John

Great. Thank you both very much. I appreciate the help.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help! Can't get program to run.

2009-05-02 Thread seanm . py
On May 2, 5:30 pm, Ned Deily  wrote:
> In article
> <8f6634a2-c977-430a-b9f2-90ef9356d...@x6g2000vbg.googlegroups.com>,
>
>  seanm...@gmail.com wrote:
> > Thank you for both for the help. I still cannot get the program to run
> > though. Below I've copied my commands and the error messages for you
> > (in IDLE then Terminal):
>
> > IDLE 2.6.2
> > >>> python module1.py
> > SyntaxError: invalid syntax
>
> The default IDLE window is a python shell window.  That is, you are
> already "inside" the python interpreter, the same as if you typed just
> "python", with no file name, in the Terminal window.  You can use that
> to execute python statements and introspect objects, among other things.  
> Try it.
>
> But, back in IDLE, ignore that window for the moment and use the Open
> command in the File Menu to select and open your file module1.py from
> whatever directory it is in.  A new window should open with the contents
> of that file.  With that window selected (click on it, if necessary),
> there should be a "Run" option in the Menu bar and under it will be a
> "Run Script" option that will cause the script to run and the output to
> appear in the shell window.  You can then explore the other options
> available in IDLE for debugging, etc.
>
> --
>  Ned Deily,
>  n...@acm.org

Awesome. I think that clears it up (at least enough for now). Thank
you both very much.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help! Can't get program to run.

2009-05-02 Thread seanm . py
On May 2, 4:30 pm, Arnaud Delobelle  wrote:
> seanm...@gmail.com writes:
> > sean-marimpietris-computer:~ seanmarimpietri$ python
> > Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
> > [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
> > Type "help", "copyright", "credits" or "license" for more information.
> >>>> python module1.py
> >   File "", line 1
> >     python module1.py
> >                  ^
> > SyntaxError: invalid syntax
>
> > Again, any help would be appreciated. Thanks.
>
> From Terminal.app, this should work:
>
> sean-marimpietris-computer:~ seanmarimpietri$ python module1.py
>
> Assuming that your module1.py file is in /Users/seanmarimpietri/
>
> --
> Arnaud

Awesome. Thank you, Arnaud. I moved the file to that folder, and I got
it to work in Terminal. However, I still can't get it to run using
IDLE. Any idea why that might be? Thanks again. -Sean
--
http://mail.python.org/mailman/listinfo/python-list


Most Basic Question Ever - please help

2009-05-02 Thread seanm . py
I am going to try posting here again with more detail to see if I can
finally get my first program to work.

I am working on a MacBook Pro with OS X 10.4.11. I opened a new window
in IDLE to create a file. The file had only one line of code and was
saved as module1.py. I saved it to Macintosh HD. The one line of code
in the file is copied below:

print 'Hello module world!'

I closed the file and tried to run it in IDLE and Terminal, but I have
had no success. I'll paste my commands and the error messages below
(for IDLE, then Terminal). Any help would be very much appreciated. I
feel like the marathon just started and I've fallen flat on my face.
Thanks.

IDLE 2.6.2
>>> python module1.py
SyntaxError: invalid syntax


sean-m-computer:~ seanm$ python
Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> python module1.py
  File "", line 1
python module1.py
 ^
SyntaxError: invalid syntax




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


Re: Help! Can't get program to run.

2009-05-02 Thread seanm . py
On May 1, 6:10 pm, Ned Deily  wrote:
> In article <7618rjf1a3t8...@mid.uni-berlin.de>,
>  "Diez B. Roggisch"  wrote:
>
>
>
> > seanm...@gmail.com schrieb:
> > > I think this is maybe the most basic problem possible, but I can't get
> > > even the most basic Python to run on OS X using Terminal or IDLE. I
> > > used the IDLE editor to create a file with one line of code
>
> > > print 'text string'
>
> > > and I saved the file as module1.py. When using terminal I entered
> > > "python" to load the interpreter or whatever and then tried
>
> > > python module1.py
>
> > > but I got an error message. I've tried using the file path instead of
> > > module1.py and that didn't work either. I've tried moving the file to
> > > different places, my desktop, hard drive, etc., and none of that
> > > worked either. In IDLE I tried similar things and only got error
> > > messages there too.
>
> > > Needless to say this is a frustrating start to learning this langauge.
> > > I'd really appreciate any help getting this to work, so I can move on
> > > the actual language. Thanks so much.
>
> > It would have helped if you had given us the *actual* error-message.
> >  From what little information you give, it appears as if you do
> > something very basic wrong - instead of doing
> > $ python
> >  >>> python mymodule.py
> > (where $ is the shell/terminal and >>> the python-prompt)
> > you either do
> > $ python
> >  >>> print "hello"
> > or
> > $ python mymodule.py
> > to execute mymodule directly.
>
> And from within OS X IDLE itself, if you create or open the file
> mymodule.py, it will be in a separate window and, as long as that window
> is selected, you can run the file directly within IDLE by selecting "Run
> Module" from the "Run" menu.   So, no need to use the Terminal if you
> don't want to.
>
> --
>  Ned Deily,
>  n...@acm.org

Thank you for both for the help. I still cannot get the program to run
though. Below I've copied my commands and the error messages for you
(in IDLE then Terminal):

IDLE 2.6.2
>>> python module1.py
SyntaxError: invalid syntax

and

sean-marimpietris-computer:~ seanmarimpietri$ python
Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> python module1.py
  File "", line 1
python module1.py
 ^
SyntaxError: invalid syntax



Again, any help would be appreciated. Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Help! Can't get program to run.

2009-05-01 Thread seanm . py
I think this is maybe the most basic problem possible, but I can't get
even the most basic Python to run on OS X using Terminal or IDLE. I
used the IDLE editor to create a file with one line of code

print 'text string'

and I saved the file as module1.py. When using terminal I entered
"python" to load the interpreter or whatever and then tried

python module1.py

but I got an error message. I've tried using the file path instead of
module1.py and that didn't work either. I've tried moving the file to
different places, my desktop, hard drive, etc., and none of that
worked either. In IDLE I tried similar things and only got error
messages there too.

Needless to say this is a frustrating start to learning this langauge.
I'd really appreciate any help getting this to work, so I can move on
the actual language. Thanks so much.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Iteration for Factorials

2007-10-22 Thread Py-Fun
On 22 Oct, 13:43, Marco Mariani <[EMAIL PROTECTED]> wrote:
> Py-Fun wrote:
> > def itforfact(n):
> > while n<100:
> > print n
> > n+1
> > n = input("Please enter a number below 100")
>
> You function should probably return something. After that, you can see
> what happens with the result you get.

Marco, Thanks for the tip.  This now works:

def itforfact(n):
while n<100:
print n
n = n+1
n = input("Please enter a number below 100")

itforfact(n)

Is it a "factorial" though?

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


Re: Iteration for Factorials

2007-10-22 Thread Py-Fun
On 22 Oct, 13:28, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Py-Fun wrote:
> > I'm stuck trying to write a function that generates a factorial of a
> > number using iteration and not recursion.  Any simple ideas would be
> > appreciated.
>
> Show us your attempts, and we might suggest a fix. Because otherwise this
> sounds suspiciously like homework.
>
> Diez

Here is my futile attempt.  Be careful with this though, I just ran
something similar and it was never ending...

def itforfact(n):
while n<100:
print n
n+1
n = input("Please enter a number below 100")

itforfact(n)

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


Iteration for Factorials

2007-10-22 Thread Py-Fun
I'm stuck trying to write a function that generates a factorial of a
number using iteration and not recursion.  Any simple ideas would be
appreciated.

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


Port Function crc_ccitt_update from C++

2007-04-01 Thread Py Thorneiro

Hi folks,

   Please, I don´t understand exactly what this function CRC CCITT UPDATE
in C++ AVR can be ported to Python..

uint16_t
crc_ccitt_update (uint16_t crc, uint8_t data)
{
  data ˆ= lo8 (crc);
  data ˆ= data << 4;
  return uint16_t)data << 8) | hi8 (crc)) ˆ (uint8_t)(data >> 4)
ˆ ((uint16_t)data << 3));
}

Source:
http://tldp.tuxhilfe.de/linuxfocus/common/src2/article352/avr-libc-user-manual-1.0.4.pdf

 In parts reason this lo8 and hi8, is there some good soul here that
can help-me with this conversion?

I try seach in Google and Koders some code that use it, but I don´t had
sucess...


Big Hugs
Thanks
Regards.


-Py -Thorneiro
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: CRC CCITT UPDATE in Python

2007-04-01 Thread Py Thorneiro

Hi Martin!

 OK, thanks; but its work in AVR... After compile it and work in agree
with the device that I need to talk, the software work fine, but I would
like port it to PC in Python...

Hi Folks,

 So sorry, but I try find it googling, searkoding (
http://www.koders.com) and try understand so bether and unhapilly don´t had
sucess... I try normally  the hands-on technique and to practise the DIY
philosophy; but in this case my mind isn´t helping me!:-)

 Please, could you help me? :-) How to port this hi8 and lo8 to Python,
is there some function similar?

Tnx,

./Fernando -Py - thorneiro -


On 4/1/07, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:



>   Please, is there here some good soul that understand this
> functions hi8 and lo8 (from GCC AVR) and can help me to port it to
> Python?
>
> uint16_t
> crc_ccitt_update (uint16_t crc, uint8_t data)
> {
>data ˆ= lo8 (crc);
>data ˆ= data << 4;
>return uint16_t)data << 8) | hi8 (crc)) ˆ (uint8_t)(data >> 4)
> ˆ ((uint16_t)data << 3));
> }

Most likely, lo8(crc) == crc & 0xFF, and hi8(crc) == (crc >> 8) & 0xFF
(the last bit masking might be redundant, as crc should not occupy more
than 16 bits, anyway).

HTH,
Martin


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

Re: smtplib starttls gmail example - comments?

2007-01-25 Thread py
Excellent imput!

I learned
- no need for trailing . and i was doing it wrong anyway.
- all those extra trys were redundant.
- the trailing comma functionality in print.
- the extra ehlo is an rfc req.

Thanks all.

-dave
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: smtplib starttls gmail example - comments?

2007-01-23 Thread py
I would love for anybody to comment on this code with regard to 
redundancy/efficiency/wordiness or whatever else.
for instance, do i understand correctly that i cant have a try: else: without 
an intervening except:?
-dave

stdout.write("calling smtp server...")
try:
server = SMTP(msgsmtp)
except:
stdout.write("FAIL.")   #using .write to avoid the implied \n with 
print
else:
server.set_debuglevel(msgdebug)
stdout.write("starting tls...")
server.ehlo(msgfrom)
try:server.starttls()
except: stdout.write("FAIL.")
else:
server.ehlo(msgfrom)   #neessary duplication (?)
stdout.write("logging in...")
try:server.login(msgfrom, msgpass)
except: stdout.write("FAIL.")
else:
stdout.write("sending...")
try:server.sendmail(msgfrom, msgto, msgtxt + "\n.\n")
except: stdout.write("FAIL.")
else:
try:
server.quit()
except sslerror:  # a known and largely ignored 
issue with early EOF in ssl protocol
stdout.write("success.")
else:
stdout.write("success.")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: smtplib starttls gmail example

2007-01-23 Thread py
Hmm, my last post seems to have been redirected to /dev/null. Anyhoo.
Jean Paul, I read your code with interest. Does twisted also raise the 
apparently well-known
and often ignored socket error, and do you supposed this error has something to 
do with the
fact that the trailing \n.\n is encrypted? the error msg reports something 
about premature eof.
altho one would suppose the commands and data are decrpyted before the smtp 
daemon
sees them

-dave
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: smtplib starttls gmail example

2007-01-23 Thread py
Hi, Jean Paul.

I read your code with interest. I wonder, does twisted also raise the socket 
error or does it know
about this apparently well-known and often ignored incompatibility between the 
standard and
the implementations?

Something else has occurred to me. After starting tls, all the xmitted commands 
and data are encrypted before they leave the client machine.
so obviously they have to be decrypted by the server's socket lib before the 
smtp daemon can do what it's supposed to do.
but i wonder if the encryption of the trailing \n.\n has something to do with 
the socket error, given that
the error msg says something about premature EOF.

-dave
-- 
http://mail.python.org/mailman/listinfo/python-list


smtplib starttls gmail example

2007-01-23 Thread py
from smtplib import SMTP
from socket import sslerror #if desired
server = SMTP('smtp.gmail.com')
server.set_debuglevel(0) # or 1 for verbosity
server.ehlo('[EMAIL PROTECTED]')
server.starttls()
server.ehlo('[EMAIL PROTECTED]')  # say hello again
server.login('[EMAIL PROTECTED]', 'yourpassword')
# i have a suspicion that smptlib does not add the required newline dot newline 
so i do it myself
server.sendmail('[EMAIL PROTECTED]', '[EMAIL PROTECTED]', message_text + 
'\n.\n')
# next line generates the ignorable socket.sslerror
server.quit()


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


Re: write an update manager in python/wxPython

2006-12-07 Thread gagsl-py
On 7 dic, 19:04, Will McGugan <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > I have a small application for which I would like to write an update
> > manager. I assume that the basics of it is to compare versions of the
> > user's current application and a new one store in a new file on a
> > particular URL.
> Dont think there is a standard way of doing it. The way I have done it
> in my applications is to keep an ini file containing the version number,
>   which is downloaded and compared against the version of the app. That
> part is trivial to implement in python with urllib. I just point the
> user at the download url when there is a new version. It would require a
> little more effort if you want to have some kind of automatic update...

There is a sample script (in tools/versioncheck in your Python
directory) you could use as a starting point. Not a big deal...

-- 
Gabriel Genellina

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


Re: SOAP Server with WSDL?

2006-12-07 Thread gagsl-py
On 7 dic, 18:52, tobiah <[EMAIL PROTECTED]> wrote:

> Actually, do I have to make a WSDL?  Do people hand write these, or
> are there tools?  I don't really need to publish an interface.  I just
> want some in house apps to communicate.
>
> I can't figure out if I want SOAP, or CORBA, or would it just be
> easier if I just starting opening sockets and firing data around
> directly.  Ideally, I'd like to share complex objects.  That's why
> I thought that I needed one of the above standards.

A few alternatives:

xml-rpc
Pros: multiplatform, multilanguage, standard, available in python std
lib, very simple to use
Cons: simple function calls only, limited argument types, no objects as
argument

Pyro 
Pros: object based, multiplatform, full python language support
(argument list, keyword arguments...)
Cons: only Python supported, non standard

CORBA is a big beast and if you don't actually need it, don't use it...

-- 
Gabriel Genellina

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


Re: Multithreaded python script calls the COMMAND LINE

2006-12-07 Thread gagsl-py
On 7 dic, 17:36, "johnny" <[EMAIL PROTECTED]> wrote:
> I have python script does ftp download in a multi threaded way. Each
> thread downloads a file, close the file, calls the comman line to
> convert the .doc to pdf. Command line should go ahead and convert the
> file. My question is, when each thread calls the command line, does one
> command line process all the request, or each thread creates a one
> command line process for themselves and executes the command? For some
> reason I am getting "File '1' is alread exists, Do you want to
> overwrite [y/n]?" I have to manually enter 'y' or 'n' for the python
> script to complete.

That depends on how you invoke it: os.system creates a new shell which
in turn creates a new process; the spawn* functions do that directly.
Anyway, if you have many conversion processes running, you should pass
them unique file names to avoid conflicts.
Where does the '1' name come from? If it's you, don't use a fixed name
- the tempfile module may be useful.

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


Re: Embedded python adding variables linking to C++-Variables / callbacks

2006-12-07 Thread gagsl-py
On 7 dic, 11:33, "iwl" <[EMAIL PROTECTED]> wrote:

> What I found out up to now is to create a class inherited from an
> fitting type
> and overwrite the __setitem__ and __getitem__ method but haven't test
> this
> yet, something like that:
>
> class test(int):
>  __setitem(self, value)__:  C-Set-Func(value)
>  __getitem(self)__: return C-Get-Func()
>
> x=test()
> x= -> C-Set-Func called
> y=x -> C-Get-Func called

Python doesn't work that way: http://effbot.org/zone/python-objects.htm

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


Re: Embedded python adding variables linking to C++-Variables / callbacks

2006-12-07 Thread gagsl-py
iwl ha escrito:

> I would like to add Variables to my embedded python which represents
> variables from my
> C++-Programm.
> I found C-Api-funcs for adding my C-Funcs to python but none to add
> variables.
> I would like some C-Function is called when the added Python-varible is
> set (LValue) and
> some other when it is read (RValue). Can I do this.
> May be I have to do this in python and call the C-Funcs from a python
> callback.

Write some C functions -callable from Python- which will be used to get
and set the variable value.
>From inside Python, declare a property with getter and setter which
will call your C functions.
This works fine for object attributes. If you want to trap references
to local or global "variables", I think you could provide customized
dictionaries for locals and globals, but I'm not sure if it works
really.

-- 
Gabriel Genellina

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


Re: Overwrite only one function with property()

2006-11-18 Thread gagsl-py
On 18 nov, 19:06, "Kai Kuehne" <[EMAIL PROTECTED]> wrote:

> It is possible to overwrite only one function with the property-function?
>
> x = property(getx, setx, delx, 'doc')
>
> I just want to overwrite setx, but when I set the others to None,
> I can't read and del the member. Any ideas or is this not possible?

Do you want to override the setter of an existing property, in a
derived class?

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


Re: compiling 2.3.5 on ubuntu

2006-07-16 Thread Py PY
Sorry to be a pest but is there anybody that could help me understand 
a) if any of this is a problem; and b) where I can learn how to fix it.

Thank you very much for any pointers.

On 2006-07-10 11:45:51 -0400, Py PY <[EMAIL PROTECTED]> said:

> (Apologies if this appears twice. I posted it yesterday and it was held 
> due to a 'suspicious header')
> 
> I'm having a hard time trying to get a couple of tests to pass when 
> compling Python 2.3.5 on Ubuntu Server Edition 6.06 LTS. I'm sure it's 
> not too far removed from the desktop edition but, clearly, I need to 
> tweak something or install some missling libs.
> 
> uname -a
> 
> Linux server 2.6.15-23-server #1 SMP Tue May 23 15:10:35 UTC 2006 i686 
> GNU/Linux
> 
> When I compile Python I get these failing
> 
> 4 skips unexpected on linux2:
> test_dbm test_mpz test_bsddb test_locale
> 
> I've got libgdbm-dev and libgdbm3 packages installed.
> 
> Help!


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


compiling 2.3.5 on ubuntu

2006-07-10 Thread Py PY
(Apologies if this appears twice. I posted it yesterday and it was held 
due to a 'suspicious header')

I'm having a hard time trying to get a couple of tests to pass when 
compling Python 2.3.5 on Ubuntu Server Edition 6.06 LTS. I'm sure it's 
not too far removed from the desktop edition but, clearly, I need to 
tweak something or install some missling libs.

uname -a

Linux server 2.6.15-23-server #1 SMP Tue May 23 15:10:35 UTC 2006 i686 
GNU/Linux

When I compile Python I get these failing

4 skips unexpected on linux2:
test_dbm test_mpz test_bsddb test_locale

I've got libgdbm-dev and libgdbm3 packages installed.

Help!

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


compiling 2.3.5 on ubuntu

2006-07-10 Thread Py Py
Hi, list.I'm having a hard time trying to get a couple of tests to pass when compling Python 2.3.5 on Ubuntu Server Edition 6.06 LTS. I'm sure it's not too far removed from the desktop edition but, clearly, I need to tweak something or install some missling libs.uname -aLinux server 2.6.15-23-server #1 SMP Tue May 23 15:10:35 UTC 2006 i686 GNU/Linux When I compile Python I get these failing4 skips unexpected on linux2:    test_dbm test_mpz test_bsddb test_localeI've got libgdbm-dev and libgdbm3 packages installed.Help! 
	
		Sneak preview the  all-new Yahoo.com. It's not radically different. Just radically better. 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Execute batch script on remote computer

2006-02-13 Thread py
WMI will work, i can create a new Win32_Process.  XML_RCP would be
nice, but probably to much for what i need.

thanks.

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


Execute batch script on remote computer

2006-02-13 Thread py
I am trying to execute a batch script on a remote computer.

The batch script looks like:

@echo off
start c:\python24\python.exe c:\a_script.py


Here's the setup:
Computer A (my computer), Computer B (the remote computer).

So I map "W:" to Computer B and then copy the batch script to Computer
B.  Then from within Python on Computer A I run:
import subprocess
subprocess.Popen("W:\\foo.bat")

However, when it runs it says it can't find c:\a_script.py.  It seems
to be trying to look
at Computer A, not Computer B.  How can I do this?

Thanks

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


Re: Create dict from two lists

2006-02-10 Thread py
Iain King wrote:
> Short answer - you can't.  Dictionaries aren't sequential structures,
> so they have no sorted form.  You can iterate through it in a sorted
> manner however, as long as you keep your list of keys:
>
> keys.sort()
> for k in keys:
> print d[k]
> 
> Iain

duh!thanks.

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


Re: Create dict from two lists

2006-02-10 Thread py
Thanks, itertools.izip and just zip work great.  However, I should have
mentioned this, is that I need to keep the new dictionary sorted.

d = {1:'first', -5 : 'negative 5', 6:'six', 99:'ninety-nine',
3:'three'}
keys = d.keys()
keys.sort()
vals = map(d.get, keys)

At this point keys is sorted [-5, 1, 3, 6, 99] and vals is sorted
['negative 5', 'first', 'three', 'six', 'ninety-nine']

Using zip does not create the dictionary sorted in this order.
new_d = dict(zip(keys, vals))

How can I use the two lists, keys and vals to create a dictionary such
that the items keep their order?

Thanks.

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


Create dict from two lists

2006-02-10 Thread py
I have two lists which I want to use to create a dictionary.  List x
would be the keys, and list y is the values.

x = [1,2,3,4,5]
y = ['a','b','c','d','e']

Any suggestions?  looking for an efficent simple way to do this...maybe
i am just having a brain fart...i feel like this is quit simple.

thanks.

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


jython/python: read file and allow read to be terminated

2006-01-27 Thread py
i need to read the contents of a file (could be 100kb, could be 500mb,
could be 1gb)...but I want to allow the read to be canceled.

for example, say a user wants to savea file...as it's saving they want
to terminate it...thus stop the read.

I was doing this:

def keepReading():
# return whether reading should continue
return readOn

data = []
f = open('somefile.zip', 'rb')
while len(data) < sizeOfFile and keepReading():
data.append(f.read(1))

however, this seems to work in python (not in jython, where I get
OutOfMemoryError).  Any suggestions on how to approach this with
perhaps a better way?

thanks

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


wxPython layout problem

2006-01-23 Thread py
I have the following code:
[code]
class MainFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title,
style=wx.DEFAULT_FRAME_STYLE |wx.NO_FULL_REPAINT_ON_RESIZE)
# build top area
topSizer = self.buildTopPanel()
# build input area
inputSizer = self.buildInputPanel()

mainSizer = wx.BoxSizer(wx.VERTICAL)
mainSizer.Add(topSizer, 1, wx.EXPAND | wx.ALL, 5)
mainSizer.Add(inputSizer, 1, wx.EXPAND | wx.ALL, 5)

p = wx.Panel(self, wx.ID_ANY)
p.SetSizer(mainSizer)

s = wx.BoxSizer(wx.VERTICAL)
s.Add(p, 1, wx.EXPAND)

self.SetAutoLayout(True)
self.SetSizer(s)
self.Layout()

def buildTopPanel(self):
p = wx.Panel(self, wx.ID_ANY)
self.text = wx.TextCtrl(p, wx.ID_ANY, style=wx.TE_MULTILINE |
wx.SUNKEN_BORDER)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.text, 1, wx.EXPAND)
return sizer

def buildInputPanel(self):
# the area to enter text
self.text2 = wx.TextCtrl(self, wx.ID_ANY, style=wx.TE_MULTILINE
| wx.SUNKEN_BORDER)

# panel to add button to
p = wx.Panel(self, wx.ID_ANY)
self.buttonClick = wx.Button(p, wx.ID_ANY, "Click")
hsizer = wx.BoxSizer(wx.HORIZONTAL)
hsizer.Add(self.buttonClick, 0, wx.ALIGN_CENTER)
p.SetSizer(hsizer)

# add the text control and button panel
box = wx.BoxSizer(wx.HORIZONTAL)
box.Add(self.text2, 1, wx.EXPAND)
box.Add(p, 0, wx.EXPAND)
return box

if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MainFrame(None, wx.ID_ANY, "Test")
frame.Show()
app.MainLoop()
[/code]

there are two problems.
1) i want the sizer (that is returned from buildTopPanel()) to fill the
screen wide/tall.  now the text control in it is very small in the
upper-left corner.

2) the scroll bars and borders on the text controls dont appear until i
mouse over them, any ideas?

thanks

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


Re: wxPython or wxWidgets

2006-01-23 Thread py
Lawrence Oluyede wrote:
> wxPython is the Python porting of wxWidgets.


got it, thanks.

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


wxPython or wxWidgets

2006-01-23 Thread py
i need to design a GUI for my python app.  i heard of wxWidgets and was
going to look into that, but then I saw wxPython.  Why would I use
wxPython over wxWidgets?

thanks

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


how to run python scripts on a website

2006-01-21 Thread py
i have a website which runs apache on linux.  it supports python (i
think via cginot sure how else).  anyway how can I go to a web page
and run a python script or something like that?  for example say i make
a script which prints out all the links on another URLhow can i run
that?


thanks!

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


jython base64.urlsafe_b64xxx

2006-01-12 Thread py
anyone know how to do perform the equivalent base64.urlsafe_b64encode
and base64.urlsafe_b64decode functions that Python has but in jython?
Jython comes with a base64 module but it does not have the urlsafe
functions.  Tried copying the pythhon base64.py to replace the Jython
one, and although it did perform the encode/decode it didnt seem to be
correctly decoded.


thanks

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


Re: how to improve this simple block of code

2006-01-11 Thread py
hanz wrote:
> x = x.rstrip('0.') # removes trailing zeroes and dots

knew there had to be a way, thanks.

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


how to improve this simple block of code

2006-01-11 Thread py
Say I have...
x = "132.00"

but I'd like to display it to be "132" ...dropping the trailing
zeros...I currently try this

if x.endswith("0"):
x = x[:len(x)-1]
if x.endswith("0"):
x = x[:len(x)-1]
if x.endswith("."):
x = x[:len(x)-1]

I do it like this because if
x = "132.15"  ...i dont want to modify it.  But if
x = "132.60" ...I want it to become "132.6"

is there a better way to do this?  It seems a bit ugly to me.

T.I.A
(thanks in advance)

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


Re: Display of JPEG images from Python

2006-01-08 Thread py pan
I remember seeing somewhere saying that the "wx.StaticBitmap" is only for small image (64x64?), is that true?On 6 Jan 2006 07:01:24 -0800, 
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
You can f.i. use wxPython (www.wxPython.org). Here is a compact andugly, but (almost) minimal, example of a python script that shows animage file:import wxa = wx.PySimpleApp
()wximg = wx.Image('img.jpg',wx.BITMAP_TYPE_JPEG)wxbmp=wximg.ConvertToBitmap()f = wx.Frame(None, -1, "Show JPEG demo")f.SetSize( wxbmp.GetSize() )wx.StaticBitmap(f,-1,wxbmp,(0,0))f.Show(True)
def callback(evt,a=a,f=f):# Closes the window upon any keypressf.Close()a.ExitMainLoop()wx.EVT_CHAR(f,callback)a.MainLoop()-svein--
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Map port to process

2006-01-05 Thread py
Is there a way in python to figure out which process is running on
which port?  I know in Windows XP you can run "netstat -o" and see the
process ID for each open portbut I am looking for something not
tied to windows particularly, hopefully something in python.

if not, any known way, such as netstat shown above, for other versions
of windows (such as 98, 2000) and even linux?

thanks

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


Re: WMI - invalid syntax error?

2006-01-03 Thread py
py wrote:
> I am going to try typing up that simple function into a new py file and
> put it on a diff. PC and try it.  I tried my current code on another
> computer and had the same issue...but I am wondering if I start anew if
> it will help.

ok, i am not sure whats going on.  I created a simple file with a
function which creates the WMI object, and I can use it, no problem.
Must be something weird, non-wmi related happening.

thanks.

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


Re: WMI - invalid syntax error?

2006-01-03 Thread py
The problem only seems to occur when importing the file and using it
that way.  It works the first time, but not the second, third, etc.  If
I run the same commands via the interpreter I have no problem.

I may end up looking into some other way of getting the list of
processesthis is real screwy.

I am going to try typing up that simple function into a new py file and
put it on a diff. PC and try it.  I tried my current code on another
computer and had the same issue...but I am wondering if I start anew if
it will help.

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


Re: WMI - invalid syntax error?

2005-12-30 Thread py
py wrote:
>Something must be happening somewhere causing it
> to get fouled up.  I'm gonna try on a different PC.

I tried on another PC, same problem.

Also, I added "reload(wmi)" before I create an instance of wmi.WMI just
to see what happens, so I hve...

import wmi

def ppn(machine=None):
try:
reload(wmi)
wmiObj = wmi.WMI(machine)
except Exception, e:
print "Error: " + str(e)

...now I get this as the error message..
Error: (-2147221020, 'Invalid syntax', None, None)

Slightly different than before...but same message.

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


Re: WMI - invalid syntax error?

2005-12-30 Thread py
Tim Golden wrote:
> 
> import wmi
> wmi._DEBUG = True
>
> c = wmi.WMI ()
> # This will print a moniker looking something like this:
> #
> winmgmts:{impersonationLevel=Impersonate,authenticationLevel=Default}/ro
> ot/cimv2
> 
>
> and let me know what comes out.

I ran it twice, first it worked, second time it didnt...
winmgmts:{impersonationLevel=Impersonate,authenticationLevel=Default}/root/cimv2
winmgmts:{impersonationLevel=Impersonate,authenticationLevel=Default}/root/cimv2

..but same moniker.  Something must be happening somewhere causing it
to get fouled up.  I'm gonna try on a different PC.

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


Re: WMI - invalid syntax error?

2005-12-30 Thread py
Tim Golden wrote:
> Could you just post (or send by private email if you prefer)
> the exact script you're running? If you want to send it
> privately, please us mail  timgolden.me.uk.

I am truly unsure what the problem could be, and the fact that the
error says "invalid syntax" ...just doesn't make much sense to me.
Perhaps I could print out the moniker and see if that looks right...any
suggestion on how to do that?

Anyway I have this:
import wmi

def ppn(machine=None):
try:
wmiObj = wmi.WMI(machine)
print "Got it:", wmiObj
except Exception, e:
print "Error:", e


This is the same code, line for line, as i am using in a bigger script.
 It's got to be something stupid...just doesn't make any sense.  Wish
the error was more specific.

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


Re: WMI - invalid syntax error?

2005-12-30 Thread py
one more note, I am using WMI v0.6 however, I also tried it with
the latest version 1.0 rc2.

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


Re: WMI - invalid syntax error?

2005-12-30 Thread py
here's the trace...

  File "MyScript.py", line 10,
wmiObj = wmi.WMI(machine)
  File "wmi.py", line 519, in __init__
handle_com_error (error_info)
  File "wmi.py", line 131, in handle_com_error
raise x_wmi, "\n".join (exception_string)
x_wmi: -0x7ffbfe1c - Invalid syntax

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


WMI - invalid syntax error?

2005-12-30 Thread py
Hi,
  I am running python 2.4.2 on win xp pro.  I have the WMI module from
Tim Golden (http://tgolden.sc.sabren.com/python/wmi.html).

I have some code which does this...

MyScript.py
--
import wmi
# the ip of my own local desktop
machine = "1.2.3.4"
try:
w = wmi.WMI(machine)  # also tried, wmi.WMI(computer=machine)
except Exception, e:
print "ERROR:", e

c:>python
>> from MyScript import *
>>> ERROR: -0x7ffbfe1c - Invalid syntax

>> import wmi
>> w = wmi.WMI("1.2.3.4")
>>

So when I import the script I get the "invalid syntax" error (which
comes from the line, w = wmi.WMI())

but in the same window if I just type it in manually I get no error.

Any ideas???

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


Re: python coding contest

2005-12-27 Thread py pan
On 12/27/05, Christian Tismer <[EMAIL PROTECTED]> wrote:
And we are of course implementing algorithms with a twisted goal-setin mind: How to express this the shortest way, not elegantly,just how to shave off one or even two bytes, re-iterating thepossible algorithms again and again, just to find a version that is
lexically shorter? To what a silly, autistic crowd of insane peopledo I belong? But it caught me, again!I personally think that it's a good practice. The experiences gatheredmight be useful in other applications in the future. That's where the
excitement of learning new things is about. Actually, I don't see so much applications
for the given problem, Something like this:http://j.domaindlx.com/elements28/wxpython/LEDCtrl.htmlconvinced me that there are application of this problem. 

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

Re: python coding contest

2005-12-27 Thread py pan
When you guys say 127~150 characters, did you guys mean usinging test_vectors.py in some way? Or there's no import at all?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: serialize object in jython, read into python

2005-12-22 Thread py
Noah wrote:
> You can give up on pickle, because pickle is only
> guaranteed to work with the exact same version of the Python
> interpreter.

:(


> How complex of a serialization do you need?

simple

I just wrote the info out to a file.  then i have a thread which reads
in the files and parses them and creates the necessary object.

thanks anyway

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


serialize object in jython, read into python

2005-12-22 Thread py
I want to serialize an object in jython and then be able to read it in
using python, and vice versa.

Any suggestions on how to do this?  pickle doesnt work, nor does using
ObjectOutputStream (from jython).

I prefer to do it file based ...something like

pickle.dump(someObj, open("output.txt", "w"))

as opposed to shelve

f = shelve.open("output.txt")
f['somedata'] = someObj

Thanks for the help in advance.

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


Thoughts on object representation in a dictionary

2005-12-09 Thread py
Say I have classes which represent parts of a car such as Engine, Body,
etc.  Now I want to represent a Car in a nested dictionary like...

{string_id:{engine_id:engine_object, body_id:body_object}}ok?

Well the other thing is that I am allowed to store strings in this
dictionary...so I can't just store the Engine and Body object and later
use them.  this is just a requirement (which i dont understand
either)...but its what I have to do.

So my question is there a good way of storing this information in a
nested dictionary such that if I receive this dictionary I could easily
pull it apart and create Engine and Body objects with the information?
Any suggestions at all?  keep in mind I am limited to using a
dictionary of strings...thats it.

Thanks for any input.

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


Re: uuDecode problem

2005-12-09 Thread py
Thanks...I think base64 will work just fine...and doesnt seem to have
45 byte limitations, etc.

Thanks.

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


Re: uuDecode problem

2005-12-09 Thread py
Alex Martelli wrote:
I suggest a redesign...!


What would you suggest?  I have to encode/decode in chunks b/c of the
45 byte limitation.

Thanks.

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


Re: uuDecode problem

2005-12-07 Thread py
Alex Martelli wrote:
> binascii.b2a_uu only works for up to 45 bytes at once; but if you were
> feeding it more than 45 bytes, this should raise a binascii.Error
> itself.
> Definitely not, given the above limit.  But I still don't quite
> understand the exact mechanics of the error you're getting.
>
>
> Alex

here is an example.

def doSomething():
data = aFile.readlines()
result = []
for x in data:
result.append(encode(x))
return result

def printResult(encodedData):
"""encodedData is a list of strings which are uu encoded"""
print decode(encodedData)

encode(data):
"""data is a string"""
if len(data) > 45:
tmp = []
for c in data:
tmp.append(binascii.b2a_uu(c))
return ''.join(tmp)
else:
return binascii.b2a_uu(data)


decode(data):
"""data is a list of strings"""
result = []
for val in data
if len(val) > 45:
response = []
for x in val:
response.append(binascii.a2b_uu(x))
result.append(response)
else:
result.append(binascii.a2b_uu(val))
return ''.join(result)

...i would use those functions like

data = doSomething()
printResult(data)

Now i get this...
"response.append(binascii.a2b_uu(x))
java.lang.StringIndexOutOfBoundsException:
java.lang.StringIndexOutOfBoundsExcep
tion: String index out of range: 1"

So the error is in the decode method .this is in Jython...perhaps
Jython doesn't handle binascii.a2b_uu ?  or perhaps since the actual
data is being encoded in python, then read in and decoded in my jython
script..that could be the problem?

thanks.

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


uuDecode problem

2005-12-07 Thread py
Hi,
  I am encoding a string such as...

[code]
data = someFile.readlines()
encoded = []
for line in data:
encoded.append(binascii.b2a_uu(stringToEncode))
return encoded
[/code]

...I then try to decode this by...

[code]
def decode(data):
result = []
for val in data:
result.append(binascii.a2b_uu(val))
return result
[/code]

this seems to work sometimesfor example a list which has a short
string in it like ["this is a test"]

however if the list of data going into the decode function contains a
bunch of elements I get the following error...

result.append(binascii.a2b_uu(val))
binascii.Error: Trailing garbage

..any idea why this is happening?  Anyone successfully use the uu to
encode/decode strings of varying length (even larger strings, more than
a few hundred characters)?

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


Re: SNMPV3

2005-12-06 Thread py
the most recent version of PySNMP (like 4.1.x) has SNMP v3 support.
(not sure if its 100% or not...check with developer).

Anyhow I think the documentation explains how to use PySNMP
(http://pysnmp.sourceforge.net/docs/4.1.x/index.html) i think the
"interface" is common amongst the different SNMP versions that are
supported by PySNMP.  So i think if you use the
CommandGenerator.nextCmd method...its the same format for snmp v2 and
v3, etc.

It took me a little bit to grasp the API but once I did it works well
(although I am not using SNMP v3)

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


Re: How to - import code not in current directory

2005-11-17 Thread py
Claudio Grondi wrote:
> so this should work in your case:
>
> import sys
> sys.path.append("C:\some\other\directory")
> import bar

...that will certainly work.  Only issue is that each time I start up
foo.py in the python shell I have to retype those three lineskind
of why I was hoping for a environment variable or path setting that i
could stick in.

This will do for now...

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


Re: How to - import code not in current directory

2005-11-17 Thread py
PYTHONPATH is perfectcheck out this link for more info..

http://docs.python.org/tut/node8.html#searchPath

I just added the environment variable (on windows) named "PYTHONPATH"
and set it to "C:\some\other\directory"

:)

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


How to - import code not in current directory

2005-11-17 Thread py
I have a python script that I want to test/debug.  It contains a class
which extends from some other class which is located in some other
python file in a different directory.

For example:

[script to test]
c:\python_code\foo.py

[needed python files]
c:\some\other\directory\bar.py

...so I want to test/debug foo.py, which needs bar.py.  foo.py imports
bar.py ...but in order to test out foo (in the python shell) I normally
copy bar.py into the same directory as foo.py...but this is painful.
Is there some way that I can have python know about the directory where
bar.py is located, like a system variable, etc?  If so, how do I set
that up?

Thanks.

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


Re: is parameter an iterable?

2005-11-15 Thread py
Thanks for the replies.  I agree with Jean-Paul Calderone's
suggestion...let the exception be raised.

Thanks.

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


subprocess.Popen - terminate

2005-11-15 Thread py
I am using subprocess.Popen to execute an executable, how can I
terminate that process when I want?

for example (on windows)

p = subprocess.Popen("calc.exe")


now say I want to kill calc.exe ...how can I do it?  By the way, I am
not looking for a windows only solution I need something that is
universal (mac, *nix, etc)

thanks

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


Re: is parameter an iterable?

2005-11-15 Thread py
Dan Sommers wrote:
> Just do it.  If one of foo's callers passes in a non-iterable, foo will
> raise an exception, and you'll catch it during testing

That's exactly what I don't want.  I don't want an exception, instead I
want to check to see if it's an iterableif it is continue, if not
return an error code.  I can't catch it during testing since this is
going to be used by other people.

Thanks for the suggestion though.

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


is parameter an iterable?

2005-11-15 Thread py
I have function which takes an argument.  My code needs that argument
to be an iterable (something i can loop over)...so I dont care if its a
list, tuple, etc.  So I need a way to make sure that the argument is an
iterable before using it.  I know I could do...

def foo(inputVal):
if isinstance(inputVal, (list, tuple)):
for val in inputVal:
# do stuff

...however I want to cover any iterable since i just need to loop over
it.

any suggestions?

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


is parameter an iterable?

2005-11-15 Thread py
I have function which takes an argument.  My code needs that argument
to be an iterable (something i can loop over)...so I dont care if its a
list, tuple, etc.  So I need a way to make sure that the argument is an
iterable before using it.  I know I could do...

def foo(inputVal):
if isinstance(inputVal, (list, tuple)):
for val in inputVal:
# do stuff

...however I want to cover any iterable since i just need to loop over
it.

any suggestions?

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


screen capture

2005-11-14 Thread py
I need to take a screen shot of the computer screen.

I am trying to use PIL and I saw there is ImageGrab...however it only
works on Windows.  Is there a platform-independent ability to work
around this?

thanks

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


parse data

2005-11-09 Thread py
I have some data (in a string) such as

person number 1

Name: bob
Age: 50


person number 2

Name: jim
Age: 39

...all that is stored in a string.  I need to pull out the names of the
different people and put them in a list or something.  Any
suggestions...besides doing data.index("name")...over and over?

thanks!

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


Re: XML GUI

2005-11-08 Thread py
wxPython sounds like it might be the ticket...especially with the XRC
files.

I plan on defining the GUI via XML, and actions in my python app.

Thanks

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


Re: XML GUI

2005-11-08 Thread py
how about wxPython?  I am interested in something that will look native
on various operating systems (win, mac, *nix).

any good tutorial on using wxPython with XML?

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


XML GUI

2005-11-08 Thread py
Looking for information on creating a GUI using a configuration file
(like an XML file or something).  Also, how do you map actions (button
clicks, menu selections, etc) to the XML?

Any other suggestions for building GUI's for Python projects...even
Jython.

Thanks

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


SPE IDE for Python

2005-11-08 Thread py
Anyone here use SPE (http://www.stani.be/python/spe/blog/). ...the IDE?

Also, anyone know if it supports CVS or has a plugin for CVS?  If not,
what do you use to get your code into CVS (via an IDE preferably)?

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


Re: yapsnmp - on windows

2005-11-01 Thread py
anyone?

py wrote:
> I have installed net-snmp and of course python on windows xp.  I
> downloaded yapsnmp (http://yapsnmp.sourceforge.net/) and I can't seem
> to use it.  It has a swig interface...but I get errors when trying to
> swig it..
>
> C:\yapsnmp-0.7.8\src>"c:\Program Files\swigwin-1.3.25\swig.exe" -python
> net-snmp.i
> net-snmp.i(29): Error: Unable to find 'asn1.h'
> net-snmp.i(30): Error: Unable to find 'snmp_api.h'
> net-snmp.i(31): Error: Unable to find 'snmp.h'
> net-snmp.i(32): Error: Unable to find 'snmp_client.h'
> net-snmp.i(33): Error: Unable to find 'mib.h'
> net-snmp.i(34): Error: Unable to find 'default_store.h'
>
> C:\yapsnmp-0.7.8\src>
> 
> ...Any ideas?  Anyone have this working on windows?

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


yapsnmp - on windows

2005-10-31 Thread py
I have installed net-snmp and of course python on windows xp.  I
downloaded yapsnmp (http://yapsnmp.sourceforge.net/) and I can't seem
to use it.  It has a swig interface...but I get errors when trying to
swig it..

C:\yapsnmp-0.7.8\src>"c:\Program Files\swigwin-1.3.25\swig.exe" -python
net-snmp.i
net-snmp.i(29): Error: Unable to find 'asn1.h'
net-snmp.i(30): Error: Unable to find 'snmp_api.h'
net-snmp.i(31): Error: Unable to find 'snmp.h'
net-snmp.i(32): Error: Unable to find 'snmp_client.h'
net-snmp.i(33): Error: Unable to find 'mib.h'
net-snmp.i(34): Error: Unable to find 'default_store.h'

C:\yapsnmp-0.7.8\src>

...Any ideas?  Anyone have this working on windows?

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


Re: SNMP

2005-10-28 Thread py
...also I am looking to work with windows, as well as linux.

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


SNMP

2005-10-28 Thread py
>From what I have seen Python does not come with an snmp module built
in, can anyone suggest some other SNMP module (preferably one you have
used/experienced)..I have googled and seen yapsnmp and pysnmp (which
seem to be the two most active SNMP modules).

Thanks

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