[Tutor] IndentationError:
Why it keeps on complaining: $ python plot-pathway.py File "plot-pathway.py", line 35 if list1[i][j]<=42: ^ IndentationError: unindent does not match any outer indentation level def PlotPathway(list1): for i in range(len(list1)): for j in range(len(list1[i])-1): if list1[i][j] != list1[i][j+1]: g.add_edge(list1[i][j], list1[i][j+1]) if list1[i][j]<=42: g.node_attr.update(color='deepskyblue',style='filled') if list1[i][j] > 42: g.node_attr.update(color='green',style='filled') I checked the indentation very carefully, seems no problems. really no clue, Thanks with best regards, ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] optimize a plot
>>> g.nodes() [u'1', u'2', u'34', u'59', u'57'] >>> for node in g.nodes(): print node Traceback (most recent call last): File "", line 2, in print node File "/usr/lib/python2.6/idlelib/rpc.py", line 597, in __call__ value = self.sockio.remotecall(self.oid, self.name, args, kwargs) File "/usr/lib/python2.6/idlelib/rpc.py", line 210, in remotecall seq = self.asynccall(oid, methodname, args, kwargs) File "/usr/lib/python2.6/idlelib/rpc.py", line 225, in asynccall self.putmessage((seq, request)) File "/usr/lib/python2.6/idlelib/rpc.py", line 324, in putmessage s = pickle.dumps(message) File "/usr/lib/python2.6/copy_reg.py", line 70, in _reduce_ex raise TypeError, "can't pickle %s objects" % base.__name__ TypeError: can't pickle PySwigObject objects >>> for node in g.nodes(): print type(node) and this problem is weird, when I run python script.py it did not show warning. well, on the same version idle, it showed above error message. Thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Clock in tkinter?
> On Wed, Nov 16, 2011 at 1:30 AM, Mic wrote: > Hi! > I am new to programming WELCOME! >and I hop this question isn’t stupid. A teacher of mine said, "The only stupid question is the one you thought of asking but did not ask!" Happy learning Asokan Pichai ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] list of objects?
On 11/15/2011 8:40 AM, Elwin Estle wrote: I am attempting to write a text based spider solitaire game. What are the rules of your version of Spider? The only spiders I know have 10 dealt piles and 1 draw pile. I think you have greatly complicated things by using classes. Consider: deck = random.shuffle(range(13)*8) # list of 108 card "indexes" in random order. values = "A23456789JQK" # display values corresponding to indexes piles = [deck[x:x+10] for x in range(0,108,10)] Anytime you want to display the value of a card use values[cardIndex] for example to display the last card in each pile: for pile in piles: print values[pile[-1]], What will your actual display look llike? Will you completely reprint it after each move, or alter it in place? How will you get the moves from the player? -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble installing Python on Win7 (not a valid Win 32 app)
Thanks. I took a look at active state once. Too much of a learning curve for me at the time. I'm not a frequent user of Python. I was on a small project that depended on 2.5.2. There were some issues with numpy, and other libs that needed to stay put. Project is pretty well gone. If not, I'm going to declare it dead. I think I'm done here with 2.5.2. I think it's time to move to 2.6 or 2.7. Now! On 11/15/2011 4:33 PM, Alan Gauld wrote: On 15/11/11 23:55, Wayne Watson wrote: I think we've exhausted ourselves. Time to ditch 2.5.2 and find a better version of Python to work on. There is nothiong wrong with Python 2.5.2, I used it for several years on Windows. But the default installation should not be setting up idle as the interpreter for .py files. However it would make more sense in 2011 to install a more recent version unless you specifically need 2.5 to work sith some old library. Otherwise 2.6 or 2.7 would be more senmsioble. Also if you are on Windows I strongly recommend the ActiveState version. Open Source purists may object but its integration with Windows is better and Pythonwin is a much better IDE than IDLE in almost every respect. I started this very simply. I just installed 2.5.2, as we know both know, and made no changes to any associations. The install made them, not me. It sounds like the install maybe got messed up somehow, I've experienced that with python before. It's possible that simply uninstalling and reinstalling a fresh version will work. But as mentioned I'd recommend getting the ActiveState distribution. HTH, -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet "My suspicion is that the universe is not only queerer than we suppose, but queerer than we can suppose." -- Physiologist and Geneticist J.B.S. Haldane 1860-1936 (Maybe not, Dr. Haldane. We have an amazing imagination) Web Page: ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble installing Python on Win7 (not a valid Win 32 app)
It was the default action before with the right-click. I don't care about double-click. I just looked on my XP, and that's the way it's done on 2.5.2 there. I have no idea how this got onto double-click. Let's not worry about it in any case. We can quibble some more, but I'm done with this effort. See my next post to Alan in a minute or two. Nevertheless, thanks for the help. That's not entirely true, actually. See, the DEFAULT association for Python files, as set by the installation, is just to run the damn things using python.exe or pythonw.exe - NOT to edit them in IDLE. By default, if you want to edit the script you right-click and select "Open in IDLE" (or you use some other editor/IDE), but if you double-click it the script just runs. What's messed with all of that is your insistence that you want IDLE to be the default action. And there's nothing wrong with that either - but you need to recognize that it is NOT the default setting, and plan accordingly. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet "My suspicion is that the universe is not only queerer than we suppose, but queerer than we can suppose." -- Physiologist and Geneticist J.B.S. Haldane 1860-1936 (Maybe not, Dr. Haldane. We have an amazing imagination) Web Page: ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble installing Python on Win7 (not a valid Win 32 app)
On 15/11/11 23:55, Wayne Watson wrote: I think we've exhausted ourselves. Time to ditch 2.5.2 and find a better version of Python to work on. There is nothiong wrong with Python 2.5.2, I used it for several years on Windows. But the default installation should not be setting up idle as the interpreter for .py files. However it would make more sense in 2011 to install a more recent version unless you specifically need 2.5 to work sith some old library. Otherwise 2.6 or 2.7 would be more senmsioble. Also if you are on Windows I strongly recommend the ActiveState version. Open Source purists may object but its integration with Windows is better and Pythonwin is a much better IDE than IDLE in almost every respect. I started this very simply. I just installed 2.5.2, as we know both know, and made no changes to any associations. The install made them, not me. It sounds like the install maybe got messed up somehow, I've experienced that with python before. It's possible that simply uninstalling and reinstalling a fresh version will work. But as mentioned I'd recommend getting the ActiveState distribution. HTH, -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble installing Python on Win7 (not a valid Win 32 app)
On Tue, Nov 15, 2011 at 3:55 PM, Wayne Watson wrote: > ... > > With fingers crossed ... > >> >> I'm going to try one last time before I give up: >> >> - Go to Control Panel\Programs\Default Programs\Set Associations. DONE >> - Highlight the line for ".py" DONE >> - Click "Change program..." DONE >> - In the "Open with" dialog, click the "Browse..." button. DONE >> - In the "Open with..." dialog, navigate to C:\Python25\Lib\idlelib DONE >> - Highlight "idle.bat" DONE >> - Click the "Open" button. DONE >> - You'll be back in the "Open with" dialog. DONE. Click OK. DONE >> >> >> If you - yet again - do something other than what I've just described, >> and then reply telling me that it didn't work, I will add you to my spam >> filter. >> > Sigh. > The .py entry shows idle.bat > OK, take a deep breath. With a right-click on a py file "Open with", > idle.bat shows as the first entry, then idle.pyw, Notepad, and finally > python.exe. If I select either idle.bat or idle.pyw, I get a cmd window > that show in the title: c:\windows\system32\cmd.exe and another "normal" > window that says, "Windows cannot find idle.pyw. Make sure you typed the > name correctly, then try again." Selecting idle.pyw, gives me a window that > tells me the app I've tried to open in IDLE is not a valid Win32 app. > > I have no idea if the Dave Angel intervention had anything to do with this. > > I think we've exhausted ourselves. Time to ditch 2.5.2 and find a better > version of Python to work on. > > > > >> You asked about the %1 %2 %3 etc. in idle.bat. Yes, those are arguments. >> From now on, when you double-click on a .py file, >> - Windows will run idle.bat and pass it the name of your .py file as its >> first (and only) argument. >> - Idle.bat will then run pythonw.exe with "idle.pyw" as its first >> argument, and the name of your .py file as its second argument. >> - Python will then run IDLE with your .py file as its first argument. >> >> I'm going to underscore this one more time, because you need to >> understand it: Python is an interpreted/scripting language, >> > Clearly that is so. > > and (except for specialty extensions like Pyrex) it does NOT compile into >> standalone executables.* >> > Again that is so. > > Windows cannot run Python code directly - Windows doesn't know what >> Python is. When you double-click on a Python file and expect Windows to do >> something with it, you have to tell Windows to open it with a program that >> Windows actually >> > Of course. > > CAN run directly - in this case, idle.bat. What you've been telling >> Windows to do, by associating .py files with idle.pyw, is to open one file >> it doesn't recognize by using another file it doesn't recognize. Don't do >> that. >> > I started this very simply. I just installed 2.5.2, as we know both know, > and made no changes to any associations. The install made them, not me. > They only came up in this thread earlier. I may have made a mistake in > doing so, but I have no idea where. Users should not have to go through the > association process unless asked to do so. There was never a message to > ask that. I've seen it on programs like Winamp, WinMediaPlayer, > RealPlayer, but not here. > > That's not entirely true, actually. See, the DEFAULT association for Python files, as set by the installation, is just to run the damn things using python.exe or pythonw.exe - NOT to edit them in IDLE. By default, if you want to edit the script you right-click and select "Open in IDLE" (or you use some other editor/IDE), but if you double-click it the script just runs. What's messed with all of that is your insistence that you want IDLE to be the default action. And there's nothing wrong with that either - but you need to recognize that it is NOT the default setting, and plan accordingly. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble installing Python on Win7 (not a valid Win 32 app)
... With fingers crossed ... I'm going to try one last time before I give up: - Go to Control Panel\Programs\Default Programs\Set Associations. DONE - Highlight the line for ".py" DONE - Click "Change program..." DONE - In the "Open with" dialog, click the "Browse..." button. DONE - In the "Open with..." dialog, navigate to C:\Python25\Lib\idlelib DONE - Highlight "idle.bat" DONE - Click the "Open" button. DONE - You'll be back in the "Open with" dialog. DONE. Click OK. DONE If you - yet again - do something other than what I've just described, and then reply telling me that it didn't work, I will add you to my spam filter. Sigh. The .py entry shows idle.bat OK, take a deep breath. With a right-click on a py file "Open with", idle.bat shows as the first entry, then idle.pyw, Notepad, and finally python.exe. If I select either idle.bat or idle.pyw, I get a cmd window that show in the title: c:\windows\system32\cmd.exe and another "normal" window that says, "Windows cannot find idle.pyw. Make sure you typed the name correctly, then try again." Selecting idle.pyw, gives me a window that tells me the app I've tried to open in IDLE is not a valid Win32 app. I have no idea if the Dave Angel intervention had anything to do with this. I think we've exhausted ourselves. Time to ditch 2.5.2 and find a better version of Python to work on. You asked about the %1 %2 %3 etc. in idle.bat. Yes, those are arguments. From now on, when you double-click on a .py file, - Windows will run idle.bat and pass it the name of your .py file as its first (and only) argument. - Idle.bat will then run pythonw.exe with "idle.pyw" as its first argument, and the name of your .py file as its second argument. - Python will then run IDLE with your .py file as its first argument. I'm going to underscore this one more time, because you need to understand it: Python is an interpreted/scripting language, Clearly that is so. and (except for specialty extensions like Pyrex) it does NOT compile into standalone executables.* Again that is so. Windows cannot run Python code directly - Windows doesn't know what Python is. When you double-click on a Python file and expect Windows to do something with it, you have to tell Windows to open it with a program that Windows actually Of course. CAN run directly - in this case, idle.bat. What you've been telling Windows to do, by associating .py files with idle.pyw, is to open one file it doesn't recognize by using another file it doesn't recognize. Don't do that. I started this very simply. I just installed 2.5.2, as we know both know, and made no changes to any associations. The install made them, not me. They only came up in this thread earlier. I may have made a mistake in doing so, but I have no idea where. Users should not have to go through the association process unless asked to do so. There was never a message to ask that. I've seen it on programs like Winamp, WinMediaPlayer, RealPlayer, but not here. * Installation bundlers like Py2EXE or GUI2EXE simply create a minimal bundle of the Python interpreter and put it in (essentially) a self-extracting Zip file. Yes, the result is an executable - usually a gigantic one - but it's not "compiling" in the usually-understood meaning of the word. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet "My suspicion is that the universe is not only queerer than we suppose, but queerer than we can suppose." -- Physiologist and Geneticist J.B.S. Haldane 1860-1936 (Maybe not, Dr. Haldane. We have an amazing imagination) Web Page: ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble installing Python on Win7 (not a valid Win 32 app)
On Tue, Nov 15, 2011 at 12:19 PM, Wayne Watson wrote: > > For py, I found \Python25\Lib\idlelib\idle.**pyw. >>> >>> Does no good to specify yet another .py file as the executable. You >> must specify a .EXE file (or .BAT, or .CMD, or very rarely, a .COM file). >> > In py land I only have py, pyc, pyw, and pyo. I've now done py and pyc as > default. Still have the same Win32 app problem. > What am I supposed to do with python.exe? It will open a DOS window with a > command >>> prompt. I can use the prompt to do arithmetic. > > Tried idle.bat moments ago. Still get Win32 app problem msg on py files. I'm going to try one last time before I give up: - Go to Control Panel\Programs\Default Programs\Set Associations. - Highlight the line for ".py" - Click "Change program..." - In the "Open with" dialog, click the "Browse..." button. - In the "Open with..." dialog, navigate to C:\Python25\Lib\idlelib - Highlight "idle.bat" - Click the "Open" button. - You'll be back in the "Open with" dialog. Click OK. If you - yet again - do something other than what I've just described, and then reply telling me that it didn't work, I will add you to my spam filter. You asked about the %1 %2 %3 etc. in idle.bat. Yes, those are arguments. >From now on, when you double-click on a .py file, - Windows will run idle.bat and pass it the name of your .py file as its first (and only) argument. - Idle.bat will then run pythonw.exe with "idle.pyw" as its first argument, and the name of your .py file as its second argument. - Python will then run IDLE with your .py file as its first argument. I'm going to underscore this one more time, because you need to understand it: Python is an interpreted/scripting language, and (except for specialty extensions like Pyrex) it does NOT compile into standalone executables.* Windows cannot run Python code directly - Windows doesn't know what Python is. When you double-click on a Python file and expect Windows to do something with it, you have to tell Windows to open it with a program that Windows actually CAN run directly - in this case, idle.bat. What you've been telling Windows to do, by associating .py files with idle.pyw, is to open one file it doesn't recognize by using another file it doesn't recognize. Don't do that. * Installation bundlers like Py2EXE or GUI2EXE simply create a minimal bundle of the Python interpreter and put it in (essentially) a self-extracting Zip file. Yes, the result is an executable - usually a gigantic one - but it's not "compiling" in the usually-understood meaning of the word. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Clock in tkinter?
On Tue, Nov 15, 2011 at 2:00 PM, Mic wrote: > Hi! > I am new to programming and I hop this question isn’t stupid. > Welcome! > I am making a small GUI program. It is supposed to have a button and a > clock in it that displays the same time as it is according to the computer. > So as far as I am concerned both the clock and the are supposed to be > widgets? > Is this a homework assignment, or just something that you're doing for fun? It seems homework-ish. We don't mind pointing you in the right direction on homework assignments, but we definitely won't do it for you. > So how do I add this clock as a widget placed next to the button? > Tkinter doesn't have a native clock widget, so if you want to make a clock you need to roll your own. > Here is the code I have written so far, that only displays a GUI > window, and a button: > > from tkinter import * > import time > > class Window(Frame): > def __init__(self,master): > super(Window,self).__init__(master) > self.grid() > self.create_widgets() > > def create_widgets(self): > self.test_button=Button(self, text="Hi") > self.test_button.grid(row=0,column=0) > > root=Tk() > root.title("Test") > root.geometry("200x200") > app=Window(root) > root.mainloop() > Giving us code (especially such a small amount) is exactly the right thing to do when you ask a question - it shows that you've tried something, and if it's broken it usually shows why it's broken. You can add text to the Label widget - and you can change the text on that widget. You're already importing the time module - for more information about what it contains, you can run the interactive interpreter and do this: >>> import time >>> help(time) Or you can look online for the commands that might help you. If you get stuck, let us know what you're doing and where you're stuck at. HTH, Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble installing Python on Win7 (not a valid Win 32 app)
For py, I found \Python25\Lib\idlelib\idle.pyw. Does no good to specify yet another .py file as the executable. You must specify a .EXE file (or .BAT, or .CMD, or very rarely, a .COM file). In py land I only have py, pyc, pyw, and pyo. I've now done py and pyc as default. Still have the same Win32 app problem. What am I supposed to do with python.exe? It will open a DOS window with a command >>> prompt. I can use the prompt to do arithmetic. Tried idle.bat moments ago. Still get Win32 app problem msg on py files. Find your python.exe and click on that, not on idle anything. After this works, you can worry about running IDLE.bat. But get something working first. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet "My suspicion is that the universe is not only queerer than we suppose, but queerer than we can suppose." -- Physiologist and Geneticist J.B.S. Haldane 1860-1936 (Maybe not, Dr. Haldane. We have an amazing imagination) Web Page: ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble installing Python on Win7 (not a valid Win 32 app)
... Now I believe I see your problem... Your "usual error message" was, I believe , that (x) is not a valid Win32 app. Python scripts are NOT Win32 apps - and IDLE itself is a Python script. You need to tell Windows to open .py files with IDLE, but first you need to tell Windows to open IDLE itself with Python. Sounds like a job for... a batch file! Fortunately, there already is one. Try assigning .py files to \Python25\Lib\idlelib\idle.bat instead. I tried the bat approach. As far as I can tell nothing has changed. Same msg if I try to open a py file with idle.pyw. It's been awhile since I used a bat file, but what are the %s for? Usually, they are arguments. Was I supposed to supply them? I used: C:\Python25\Lib\idlelib>idle.bat C:\Python25\Lib\idlelib> If for some reason it doesn't exist, you can create one with the following contents: @echo off rem Start IDLE using the appropriate Python interpreter set CURRDIR=%~dp0 start "IDLE" "%CURRDIR%..\..\pythonw.exe" "%CURRDIR%idle.pyw" %1 %2 %3 %4 %5 %6 %7 %8 %9 -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet "My suspicion is that the universe is not only queerer than we suppose, but queerer than we can suppose." -- Physiologist and Geneticist J.B.S. Haldane 1860-1936 (Maybe not, Dr. Haldane. We have an amazing imagination) Web Page:___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Clock in tkinter?
Hi! I am new to programming and I hop this question isn’t stupid. I am making a small GUI program. It is supposed to have a button and a clock in it that displays the same time as it is according to the computer. So as far as I am concerned both the clock and the are supposed to be widgets? So how do I add this clock as a widget placed next to the button? Here is the code I have written so far, that only displays a GUI window, and a button: from tkinter import * import time class Window(Frame): def __init__(self,master): super(Window,self).__init__(master) self.grid() self.create_widgets() def create_widgets(self): self.test_button=Button(self, text="Hi") self.test_button.grid(row=0,column=0) root=Tk() root.title("Test") root.geometry("200x200") app=Window(root) root.mainloop() Thank you for your help! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble installing Python on Win7 (not a valid Win 32 app)
On 11/15/2011 10:47 AM, Wayne Watson wrote: > Highlight the line for ".py". Click the button (yes, the one that says "Change > program..."). You'll Yes, did that. > get another dialog box, and in that one there will be a button labeled > "Browse". Click it. This will open up an "Open with..." dialog box, which will > default to the Program Files folder. That's Yes, did that. > probably NOT where your Python install is located - by default, Python 2.5 > would be installed in C:\Python25 - but it's up to you to figure out where you > installed it. Once you've found it, For py, I found \Python25\Lib\idlelib\idle.pyw. Does no good to specify yet another .py file as the executable. You must specify a .EXE file (or .BAT, or .CMD, or very rarely, a .COM file). Find your python.exe and click on that, not on idle anything. After this works, you can worry about running IDLE.bat. But get something working first. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] run excel macro from python
On 15/11/11 16:07, Pirritano, Matthew wrote: Pythonistas, I am running an excel macro from python with the following code: There are some Excel/Python users here so you might get a good reply, but you might also like to try a Python Windows mailing list/forum, where are more likely to be experts available. HTH, -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] optimize a plot
On 15/11/11 14:34, lina wrote: Sorry for some not mature questions asked before, fixed now by: def PlotPathway(list1): for i in range(len(list1)): for j in range(len(list1[i])-1): if list1[i][j] != list1[i][j+1]: if ((int(list1[i][j]))< 43 and (int(list1[i][j-1]))< 43): g.add_edge(list1[i][j], list1[i][j+1]) for i in range(43,84): if g.has_node(i): g.delete_node(i) g.draw('graph4.png', prog="dot") just still don't get why the "if" does not work as expected. Sorry, I haven't been following you earlier thread. Which 'if'? There are 3 to choose from. And how did you expect it to behave, and what is it doing that you didn't expect? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] run excel macro from python
Pythonistas, I am running an excel macro from python with the following code: The problem I'm having is that when I try to run this function I get a dialog window that pops up titled: "Update Values: Personal.xls" When I try to cancel out of it I get directed to a type mismatch in the excel macro. The program is very long so I won't paste the whole thing here, just the call to the excel macro. What seems key is that the macro runs fine in excel. And I've run excel macros from python before. The only difference is that now the macro also calls some excel user defined functions. Since they live in Personal.xls I'm thinking that is the wrinkle here. All of my searching has led me nowhere. Has no one ever had this issue? You'll note the excessive closing language in the function. I thought that maybe what was happening is that more than one instance of excel was open and that was causing a problem with accessing personal.xls, as will happen if you try to manually open more than one instance of excel in windows. def runExcelMacro(): excel = win32.Dispatch("Excel.Application") excel.Visible = 0 fTest = excel.Workbooks.Add("D:\\Data\\Excel\\Blank_Summary_Report_Template_Macr o_2014.xls") macName = "macroAllFiles" macName = fTest.Name + '!' + macName print macName excel.Run(macName) excel.DisplayAlerts = 0 fTest.Close(1) excel.Quit() del excel Any ideas!? Thanks Matt Matthew Pirritano, Ph.D. Research Analyst IV Medical Services Initiative (MSI) Orange County Health Care Agency (714) 568-5648 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble installing Python on Win7 (not a valid Win 32 app)
Before reading my response below, let me note how things look on my XP laptop--for what it's worth. I happen to be using 2.4 there. When I look at a folder of py programs there, the icon is something like a lizard for each program. If I right-click on a py file, a list appears, and I'm asked if I want to Edit with IDLE, ..., ..., Edit with. All works fine. In Win 7, each file has something like a small window icon next to it. When I right-click, the items at the top are Open, Open with jEdit (I just started using it yesterday), ... Open with, ..., blah, blah. Open with has four choices: idle.pyw, Notepad, python.exe, and Choose default program. ... continuing to what I observed at your request. If you can open a command prompt and go to C:\Temp (or some other arbitrary folder), type "python", and get the Python prompt, then your search path is working properly. Well, that works. In any case, click "Change program...", then "Browse" to the current proper locations, and click OK. This should (finally) fix your problem... Change Program? Do you mean on the installed program list? I meant exactly what I typed. On the very screen we were just discussing - with the list of extensions (.py, .pyc, etc.) there is a button labeled "Change program..." Yes, in the upper right corner. Highlight the line for ".py". Click the button (yes, the one that says "Change program..."). You'll Yes, did that. get another dialog box, and in that one there will be a button labeled "Browse". Click it. This will open up an "Open with..." dialog box, which will default to the Program Files folder. That's Yes, did that. probably NOT where your Python install is located - by default, Python 2.5 would be installed in C:\Python25 - but it's up to you to figure out where you installed it. Once you've found it, For py, I found \Python25\Lib\idlelib\idle.pyw. I then opened just_fun.py program with idle.pyw, and got the usual error message. highlight python.exe and click the "Open" button. Click "OK" to get back to the list of extensions. Repeat the process for ".pyc", ".pyo", and ".pyw". The uninstall/install should have fixed this, but there are a lot of things that could interfere - perhaps you didn't run it as Administrator, perhaps it tripped over your previously-modified setting, perhaps the installer is buggy, perhaps gremlins are trying to mess with your head...? On Win7, I think I'm always the administrator. Everything gets installed from my userid. ... -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet "My suspicion is that the universe is not only queerer than we suppose, but queerer than we can suppose." -- Physiologist and Geneticist J.B.S. Haldane 1860-1936 (Maybe not, Dr. Haldane. We have an amazing imagination) Web Page:___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: Re: [python-win32] Handling a Unicode Return using Pyodbc
[cc-ing back to the *correct* list in case other readers find it helpful...] On 15/11/2011 15:16, Tony Pelletier wrote: Thanks, Tim! This is working brilliantly Slow, but working..:) I can go from here and see if there's a way to speed it up. Well you've got a few options, although an amount depends on how much control you have over your data and how well you can predict. One option is to encode at SQL Server level: CAST your NVARCHAR to VARCHAR as part of the your query, eg: SELECT contacts.id, name = CAST ( contacts.name COLLATE SQL_Latin1_General_CP1_CS_AS AS VARCHAR (200) ) FROM contacts This will bring the text in as bytes encoded Latin1 which you can then write directly to the csv without the encoder. Without having tested this, I imagine it would be faster than encoding blindly at the Python end since it'll happen lower down the stack and you're pinpointing the data rather than running through all the columns on the offchance of finding one which is unicode. An alternative is to arrange something equivalent at the Python end -- ie have specific encoders for different rows which can target the specific columns which are known to be NVARCHAR. TJG ___ python-win32 mailing list python-wi...@python.org http://mail.python.org/mailman/listinfo/python-win32 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] optimize a plot
Sorry for some not mature questions asked before, fixed now by: def PlotPathway(list1): for i in range(len(list1)): for j in range(len(list1[i])-1): if list1[i][j] != list1[i][j+1]: if ((int(list1[i][j])) < 43 and (int(list1[i][j-1])) < 43): g.add_edge(list1[i][j], list1[i][j+1]) for i in range(43,84): if g.has_node(i): g.delete_node(i) g.draw('graph4.png', prog="dot") just still don't get why the "if" does not work as expected. On Tue, Nov 15, 2011 at 10:19 PM, lina wrote: > > > I have a little issue regarding this one, the updated code: > > def PlotPathway(list1): > > for i in range(len(list1)): > for j in range(len(list1[i])-1): > if list1[i][j] != list1[i][j+1]: > if(int(list1[i][j])) < 43: > if(int(list1[i][j-1])) < 43: > g.add_edge(list1[i][j], list1[i][j+1]) > g.draw('graph4.png', prog="dot") > > > I am confused, why this one still include the digital bigger than 43? > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] list of objects?
On Tue, Nov 15, 2011 at 8:40 AM, Elwin Estle wrote: > I am attempting to write a text based spider solitaire game. I have a > pretty simple card class, and a deck class, which has a list of card > objects, which are shuffled, then individual elements are put into > self.dealt, which is a 'list of lists' when the cards are dealt. > > I am trying to control the visibility of the cards. There is a small > "for" loop in the "deal" method of the deck class, this is intended to > toggle the visibility of four of the cards. It does that just fine, but > for some reason, it seems to be randomly toggling the visibility of other > cards in the self.dealt list and I am thoroughly confused as to why that > is. Is it something to do with the way objects are referenced? Is my list > of card objects a bad way to approach this? > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > A few thoughts first: class Card(object): def __init__(self): self.value = '' self.display = 'X' I would change the above to: class Card(object): def __init__(self, value): self.value = value self.display = 'X' (because you always have a card with a value) Which allows you to save a line here: for value in values: card = Card(value) card_list.append(card) like that Another idea would be to use "extend" here: values = [] for i in range(1, 11): values.append(str(i)) values.append('J') values.append('Q') values.append('K') So, you would do something like this instead: mylist = range(1, 11) mylist.extend(['J', 'Q', 'K']) for i in mylist: values.append(str(i)) What extend does is it extends one list with another list. Also, you can build the string conversion into the card class: Further saving you the above loop: class Card(object): def __init__(self, value): self.value = str(value) self.display = 'X' and then in the create_cards def: mylist = range(1, 11) mylist.extend(['J', 'Q', 'K']) #for i in mylist: #values.append(str(i)) for value in mylist: card = Card(value) card_list.append(card) (as an aside, I'm not sure why you do this: card_list = card_list * 8 if you need two decks, I think you should have a variable like 4*decks so you can shuffle the right amount of decks) I don't think you need to shuffle twice here (which in turn calls into question why you need a separate method, but maybe you were going to build on it - i do that all the time): def shuffle(self): random.shuffle(self.cards) #random.shuffle(self.cards) Now onto your question: You can see that there are four card values that are shown visible in any given run. There are always four values and they are always random from run to run. If you comment out this loop #for index, card in enumerate(self.dealt[5]): #print index, card #self.dealt[5][index].display = self.dealt[5][index].value You won't get that anymore. If you want to control whether to display any particular card or not, I would add a variable to the display_cards method: def display_cards(self, display = True): for row in self.dealt: for card in row: if display: print '%5s ' % card.display, else: print '%5s ' % card.value, print '' Or you can add another value to the card class, if you want to control the display of cards on a unique basis: class Card(object): def __init__(self, value): self.value = str(value) self.display = 'X' self.display_or_value = True then you can change your method above to be: def display_cards(self): for row in self.dealt: for card in row: if card.display_or_value: print '%5s ' % card.display, else: print '%5s ' % card.value, print '' Long story short, if I wanted to control the visibility of any card, I would do it within the Card class (since presumably that is an attribute of any given card - think about it in real life, a card can be up, or a card can be down, yet it still retains its other properties, like color, value, creases, etc) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] list of objects?
Hi Elwin, On 15 November 2011 13:40, Elwin Estle wrote: > I am attempting to write a text based spider solitaire game. I have a > pretty simple card class, and a deck class, which has a list of card > objects, which are shuffled, then individual elements are put into > self.dealt, which is a 'list of lists' when the cards are dealt. > > I am trying to control the visibility of the cards. There is a small > "for" loop in the "deal" method of the deck class, this is intended to > toggle the visibility of four of the cards. It does that just fine, but > for some reason, it seems to be randomly toggling the visibility of other > cards in the self.dealt list and I am thoroughly confused as to why that > is. Is it something to do with the way objects are referenced? Is my list > of card objects a bad way to approach this? > Off the top of my head, your problem is likely due to the line that reads: card_list = card_list * 8 What this will do is put the *same* set of card objects in the list to begin with, into a new card_list 8 times over. So the *same* Jack (for example) will appear 8 times in the resulting list. This list, card_list, is the list that implements then later on sliced in your deal method. So, when you then set the cards in the dealt hand to visible in your self.dealt[5] loop, because these same cards (card objects) also are part of the other piles/hands, they also appear visible elsewhere when the display method is called. To fix: Replace the line above (e.g. card_list = card_list * 8) with something that explicitly constructs new cards 8 times, thereby not holding mutliple refernces from seperate piles to the same card, then you should have no further issues. Maybe loop 8 times and make a function of te preceding code etc. Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] list of objects?
I am attempting to write a text based spider solitaire game. I have a pretty simple card class, and a deck class, which has a list of card objects, which are shuffled, then individual elements are put into self.dealt, which is a 'list of lists' when the cards are dealt. I am trying to control the visibility of the cards. There is a small "for" loop in the "deal" method of the deck class, this is intended to toggle the visibility of four of the cards. It does that just fine, but for some reason, it seems to be randomly toggling the visibility of other cards in the self.dealt list and I am thoroughly confused as to why that is. Is it something to do with the way objects are referenced? Is my list of card objects a bad way to approach this? import random class Card(object): def __init__(self): self.value = '' self.display = 'X' class Deck(object): def __init__(self): self.cards = self.create_cards() self.shuffle() self.dealt = [] self.draw_piles = [] self.deal() def create_cards(self): card_list = [] values = [] for i in range(1, 11): values.append(str(i)) values.append('J') values.append('Q') values.append('K') for value in values: card = Card() card.value = value card_list.append(card) card_list = card_list * 8 return card_list def shuffle(self): random.shuffle(self.cards) random.shuffle(self.cards) def deal(self): self.dealt.append(self.cards[0:10]) self.dealt.append(self.cards[10:20]) self.dealt.append(self.cards[20:30]) self.dealt.append(self.cards[30:40]) self.dealt.append(self.cards[40:50]) self.dealt.append(self.cards[50:54]) self.draw_piles.append(self.cards[54:64]) self.draw_piles.append(self.cards[64:74]) self.draw_piles.append(self.cards[74:84]) self.draw_piles.append(self.cards[84:94]) self.draw_piles.append(self.cards[94:105]) for index, card in enumerate(self.dealt[5]): self.dealt[5][index].display = self.dealt[5][index].value def display_cards(self): for row in self.dealt: for card in row: print '%5s ' % card.display, print '' mydeck = Deck() mydeck.display_cards() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trouble installing Python on Win7 (not a valid Win 32 app)
On Mon, Nov 14, 2011 at 7:09 PM, Wayne Watson wrote: > > On 11/14/2011 6:17 PM, Marc Tompkins wrote: > > On Mon, Nov 14, 2011 at 4:55 PM, Wayne Watson < > sierra_mtnv...@sbcglobal.net> wrote: > >> >> On 11/14/2011 4:04 PM, Marc Tompkins wrote: >> >> On Mon, Nov 14, 2011 at 4:00 PM, Wayne Watson < >> sierra_mtnv...@sbcglobal.net> wrote: >> >>> I do not see Python listed there. I see Word Pad, Winamp, Paint, ... >>> >>> I'm at CP/All CP Items/Default prgrms/Set Defaults >>> >> >> My bad. It's Control Panel\Programs\Default Programs\Set Associations. >> >> (I could be wrong, but wasn't this all in one place in previous >> versions...?) Anyway, scroll down to .py/.pyc/.pyo/.pyw, and I bet you'll >> find it pointing to a no-longer-valid installation. >> >> py is listed as idle.pyw >> > This is NOT the default behavior (the default is python.exe) - I suspect > you must have changed this for convenience when you first installed your > old version of Python. > > >> pyw as pythonw.exe (no console) >> pyc/pyo as python.exe. >> > > Whoops, pyo/c are compiled python file. > "Compiled" doesn't mean "standalone". They still have to be opened with the Python interpreter (python.exe). > > It's stupid and irritating, but Windows only gives you the executable name > - not the path. Out of curiosity, does it show you the correct icons, or > does it show you some generic Windows program icon, or something broken? > > The icons look python-ish. I just used Win7 magnifier. Py looks like a > window with a red spot on the left and blue one on the right. pyc looks > like a blue and a yellow snake of some sort one top of one another. > It was just curiosity - having normal-looking icons is no guarantee of success... > > I tried adding python25 to the path as suggested by Wayne Werner. It had > no affect. > "Path" can refer to the location of a particular file, or to the "search path." The sense I intended means the actual location of that file; on my machine I have several versions of python.exe in different places (C:\cygwin\bin, C:\Program Files (x86)\Inkscape\python, C:\Python27) but the only one that matters for our current purpose is the one pointed to by the entry in Default Programs - and the path to that one is "C:\Python27\python.exe". Wayne was referring to the "search path" - also usually shortened to just "path". When you type something at the command prompt, Windows (or DOS, or Linux, or whatever) tries to match it against its list of built-in commands; if it's not a match, then it looks for matching executable files in each of the folders in the search path*, and runs the first match it finds; if it doesn't find a match, you get an error message. *In DOS and Windows, the current working directory is tried before the search path; in *nixes, you need to prepend "./" if you want to run a file in the current folder. If you can open a command prompt and go to C:\Temp (or some other arbitrary folder), type "python", and get the Python prompt, then your search path is working properly. The default program/file association in Windows short-circuits the search path; you specify exactly which executable, in what specific location, you want Windows to use to open certain types of files. That's why Wayne's advice had no effect. > > In any case, click "Change program...", then "Browse" to the current > proper locations, and click OK. This should (finally) fix your problem... > > Change Program? Do you mean on the installed program list? > I meant exactly what I typed. On the very screen we were just discussing - with the list of extensions (.py, .pyc, etc.) there is a button labeled "Change program..." Highlight the line for ".py". Click the button (yes, the one that says "Change program..."). You'll get another dialog box, and in that one there will be a button labeled "Browse". Click it. This will open up an "Open with..." dialog box, which will default to the Program Files folder. That's probably NOT where your Python install is located - by default, Python 2.5 would be installed in C:\Python25 - but it's up to you to figure out where you installed it. Once you've found it, highlight python.exe and click the "Open" button. Click "OK" to get back to the list of extensions. Repeat the process for ".pyc", ".pyo", and ".pyw". > > > The uninstall/install should have fixed this, but there are a lot of > things that could interfere - perhaps you didn't run it as Administrator, > perhaps it tripped over your previously-modified setting, perhaps the > installer is buggy, perhaps gremlins are trying to mess with your head...? > > Probably the latter. :-) Well, I may just punt and go to a 64-bit > install. Maybe up matters by going to 2.6. I think my 2.5.2 need may have > disappeared. > A 64-bit install will NOT make things any simpler; quite the reverse, in fact. . But upgrading to a newer version is definitely a good idea. Why not 2.7, which is current?
Re: [Tutor] Cython vs Python-C API
On Tue, Nov 15, 2011 at 10:26 AM, Stefan Behnel wrote: > Dario Lopez-Kästen, 15.11.2011 09:33: > >> On Tue, Nov 15, 2011 at 9:09 AM, Stefan Behnel wrote: >> >> cubic spline interpolation >>> >> > No, I didn't. > > Stefan > > Oops, apologies. My reply was meant for Jaidev (OP), but I got the quoting wrong. /dario ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Cython vs Python-C API
Dario Lopez-Kästen, 15.11.2011 09:33: On Tue, Nov 15, 2011 at 9:09 AM, Stefan Behnel wrote: cubic spline interpolation No, I didn't. Stefan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Handling a Unicode Return using Pyodbc
On 14/11/2011 21:43, Tony Pelletier wrote: Good Afternoon, I'm writing a program that is essentially connecting to MS SQL Server and dumping all the contents of the tables to separate csv's. I'm almost complete, but now I'm running into a Unicode issue and I'm not sure how to resolve it. I have a ridiculous amount of tables but I managed to figure out it was my Contact and a contact named Robert Bock. Here's what I caught. (127, None, u'Robert', None, u'B\xf6ck', 'uCompany Name', None, 1, 0, 327, 0) The u'B\xf6ck' is actually Böck. Notice the ö My problem is I'm not really sure how to handle it and whether or not it's failing on the query or the insert to the csv. The Exception is: 'ascii' codec can't encode character u'\xf6' in position 1: ordinal not in range(128) Thanks for producing a thinned-down example. If I may take this at face value, I assume you're doing something like this: import csv # # Obviously from database, but for testing... # data = [ (127, None, u'Robert', None, u'B\xf6ck', 'uCompany Name', None, 1, 0, 327, 0), ] with open ("temp.csv", "wb") as f: writer = csv.writer (f) writer.writerows (data) which gives the error you describe. In short, the csv module in Python 2.x (not sure about 3.x) is unicode-unaware. You're passing it a unicode object and it's got no way of knowing what codec to use to encode it. So it doesn't try to guess: it just uses the default (ascii) and fails. And this is where it gets just a little bit messy. Depending on how much control you have over your data and how important the unicodeiness of it is, you need to encode things explicitly before they get to the csv module. One (brute force) option is this: def encoded (iterable_of_stuff): return tuple ( (i.encode ("utf8") if isinstance (i, unicode) else i) for i in iterable_of_stuff ) # # ... other code # writer.writerows ([encoded (row) for row in data]) This will encode anything unicode as utf8 and leave everything else untouched. It will slow down your csv generation, but that might well not matter (especially if you're basically IO-bound). TJG ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Cython vs Python-C API
Hi, just a thought - have you looked at NumPy/SciPy? Perhaps there already is an API in C that does what you need, sufficiently well/fast? http://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html It is part of the NumPy/SciPy package(s). http://www.scipy.org/ /dario On Tue, Nov 15, 2011 at 9:09 AM, Stefan Behnel wrote: > cubic spline interpolation ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Cython vs Python-C API
Jaidev Deshpande, 14.11.2011 21:30: I need to perform cubic spline interpolation over a range of points, and I have written the code for the same in C and in Python. The interpolation is part of a bigger project. I want to front end for the project to be Python. Ideally I want Python only to deal with data visualization and i/o, and I'll leave the computationally expensive part of the project to C extensions, which can be imported as functions into Python. To this end, the interpolation can be handled in two ways: 1. I can either compile the C code into a module using the Python-C/C++ API, through which I can simple 'import' the required function. 2. I can use the Python code and extend it using Cython. 3. use the existing C code and wrap it with Cython, likely using NumPy to pass the data, I guess. Why write yet another version of your code? I would strongly suggest not to put C-API calls into your C code. It will just make it less versatile (e.g. no longer usable outside of CPython) and generally harder to maintain. Stefan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor