I started this thread as soon as i noticed something up.
txwooley commented: Thanks. i'll try that out +1
Nick Evan commented: The newbies continue to grow more lazy +16
vegaseat commented: good refs +11
I started this thread as soon as i noticed something up.
Hows about i try and make a thread in the forum python with some code tags in it just for a test? Is that alright?
Well this was fun, i made myself a little list comprehension to do this for me :)
#Your list is called f in my case
>>> f = [150,2,16,5,5,1,3,2,1,3,6,6]
>>> print [str(g+1)+" : "+str(f.count(g+1)) for g in range(min(f)-1,max(f)) if f.count(g+1) > 0]
['1 : 2', '2 : 2', '3 : 2', '5 : 2', '6 : 2', '16 : 1', '150 : 1']
So you could appropriate that to do other things but at the moment it just outputs to the screen but im sure it could be used in other ways.
Oh and if there are huge differences between the lowest number and the highest number then maybe xrange would be more suitable. Also notice if there are no counts for the number then it is not added!
Wow, that was fun! :) Hope it helps someone
This is the link, but i just went for having code tags rather then code=python because it wasnt working.
Im getting it again! Now i took a screenshot this time. The code-tag you see at the top is inside noparse code tags so it shouldnt be doing anything and yet its still happening! I had to change it to just code rather than code=python otherwise nothing would work. aah i thought this problem would go away quickly, it seems to be sticking around longer than usual.
Aww you were so close, your code tags are almost perfect. All you have to do is have the [/code] tag on its own line. Just repost the code like that and it will have the right indentation and make it easier to us to help you.
As for printing the value of a variable, you can do that by just going
print pwin
Without the "" signs it looks to try and print a variable if you have one :)
Hope that helps
But there also is the GUI Synaptic Package Manager on Ubuntu, thats really nice to start with, it gets all of the dependencies. It is search-able and categorised.
You find it in System -> Administration -> Synaptic Package Manager
Thats what i use if i cant find it with the aptitude search. :)
Hope that helps
Yeah i used to get that a lot with IDLE. I did the same thing i outlined above and that fixes that problem for me. Hopefully it works for someone else as well!
Just search this website, we have loads of threads on the pros and cons of many other IDE's and im with Jlm. IDLE isnt good enough when programs get complicated. Its best to try something else.
Usually this is fixed pretty easily. Shut down all IDLE's open, and any other programs that could be using python. Then you proceed to the task manager (CTRL+ALT+DEL) and go to the processes tab.
End any processes that have python.exe or pythonw.exe
Once that is all done, try restarting IDLE
Hope that helps
Wait.. suddenly seems to have been fixed.. Nevermind.
Hi,
I was just posting on the python forum when i tried posting python code and it came out weirdly. I shall show an example. This is not with any noparse or anything. And it dosent wrap it in code tags correctly. You just see the text code=python
print "Hello world"
Just wondering if its just me?
could you post there error you are getting?
oh and instead of
xy=(1,1)
xy=list(xy)
You can just go
xy = [1,1]
And then it is a list already
Really i think naming your son/daughter something like adolf or the like is more then child abuse. Its stuck with them their whole life (unless they change it) so its kinda whole life abuse, not just child abuse :P
Yeah shadwickman. I have a funny feeling that it is not python. I get a clue from the *endif and stuff like that...
Somebody should make a sticky thread titled "Can python do this?" with a single one-word post that reads: "Yes."
Yeah but a quick no for "Can python make a 3d world that i can walk around in?" or something to the like. That is unless you are really into it and want to experiment with pyOpenGL
Hi
Just about a week ago i hooked up my VGA cable to my laptop instead of my desktop. Then i turned on the desktop just to make all the network shares available. But then i about two days ago i tried to put the monitor back to the desktop but whenever i get past the windows loading screen it blanks out.
So i started it in safe mode. There i get another issue, it takes about an hour and a half to turn on. It loads all of the drivers and then gets to mup.sys and hangs. It dosent do anything for ages.
So i was wondering what is my best plan of attack? Should i just image the harddrive and reformat? is there a better way, i would rather not lose my data. :)
Cheers
Paul
Yeah i got a Dell inspron mini 9. One of the netbooks and it runs linux so well. I spent ages getting confused about how to install applications until about a week later i found the add/remove programs item. Woops!
But i love its speed and its community. Hope you have fun with ubuntu! :)
What GUI engine are you talking about? No-one can help with that little information. Spend a little more time on your question and the answer will come a lot quicker.
Im pretty sure that using the Image module is unnessicary for that. I think you can just use os and go:
import os
os.startfile("image.jpg")
Yep, just checked, it works perfectly on my computer.
def bubblesort(list):
for passes in range(len(list)-1, 0, -1):
for index in range(passes):
if list[index] < list[index + 1]:
list[index], list[index + 1] = list[index + 1], list[index]
return list
print bubblesort([3,2,66,5,22,62,61,16])
The return statement can be printed just with the keyword print.
I dont know if that is exactly what you want but if not, just ask a more specific question. ;)
I googled "hard disk serial number python" and came up with something that did this:
import win32api
print win32api.GetVolumeInformation("C:\\")
It prints out a number of things like the file system and name, im not sure if it has the serial number but thats what other people on the python mailing list thought that it might be. So give it a shot. For this you need the Mark Hammond modules for windows. That includes the win32api
http://starship.python.net/crew/mhammond/win32/Downloads.html
Hope that helps. If not have a bit of a google yourself. :) Just to check
python is really useful when it comes to saving files. There is a csv module if i am not wrong. But you can do simple text file manipulation with just standard python.
#open file.txt and set to write (w) mode
f = open("file.txt",'w')
#write lines to file, need to state the new line with a new line character
f.write("First line\n")
f.write("Second Line\n")
#close the file. This saves all data to the file and frees it up
f.close()
Just adapt that so instead of printing user you are writing the user to the text file! :)
Hope that helps
Hi, it would be really handy if you could post your code. That way we can look at it and try and debug it that way.
There are a couple of issues i can see. The first of which is a lack of code tags.
[code=python]
[/code]
This is the corrected code.. i think, some indentation might be out depending on when i thought a certain loop might end.
def grayscale_progress(path,imagelist):
app=wx.PySimpleApp()
dialog=wx.ProgressDialog("Grayscaling", "Progress", len(imagelist), style=
wx.PD_ESTIMATED_TIME
| wx.PD_REMAINING_TIME
| wx.PD_AUTO_HIDE)
count = 0
for num,images in enumerate(imagelist):
gray = Image.open(imagelist[num]).convert("L")
gray.save(os.path.join(path,images))
count += 1
dialog.Update(count)
wx.MilliSleep(500)
dialog.Destroy()
def check(path,imagelist):
app = wx.PySimpleApp()
frame=wx.Frame(None,-1,"Test",size=(250,150))
panel=wx.Panel(frame,-1)
label=wx.StaticText(panel,-1,"What to do next?",(35,20))
button=wx.Button(panel,-1,"Apply",(90,90))
gray=wx.CheckBox(panel,-1,"Gray",(35,40),(150,30))
def onclick(event):
if gray.GetValue():
grayscale_progress(path,imagelist)
frame.Destroy()
button.Bind(wx.EVT_BUTTON,onclick)
frame.Show()
app.MainLoop()
The first problem i see is
button.Bind(wx.EVT_BUTTON,onclick)
The first problem with that line is that if you want to bind a button to an event when the button is clicked you use the event wx.EVT_LEFT_DOWN. This will now call the event when you click down.
The second issue i see is the fact that the variable button is made inside of a function and you are accessing it from outside of that function. This is an issue with scope of a variable. In this case i would recommend that you either make the variable button outside of any functions or classes, making it global. Or you could add global button
to the start of the function check.
This is not the only place where we get this issue. It is the same with a lot of the variables like frame, panel, label and gray.
The other …
Yeah i spent about 3 weeks a while ago trying to work out pyGL but there was absolutely no documentation or tutorials to do so i was stuck and there really was no way for me to learn. IMHO i think you should probably use something like VPython or another language.
Ah just a simple misunderstanding. Firstly you can do it this way
n = input("Enter your number: ")
print(n+2)
But that wont work with python 30. Also in python 2.x people dont usually like the input() function as it evaluates the input. So if i typed 2*7 it would return 14 rather than just an 2 or 7. So what we use it
n = int(raw_input("enter your number: "))
But to make it work with python 30 we need to remember that with python 30 the input statement now is like the python 2.x raw_input statement so we can go:
n = int(input("Enter your number: "))
print (n+2)
Hope that solves your problem! :)
Or you could use formatted strings! Have a look at the tutorial here:http://diveintopython.org/native_data_types/formatting_strings.html
l = [['a', 'b', 'c', 'd'],['e','f','g','h']]
for item in l:
print "%s %s %s %s" %(item[0], item[1],item[2],item[3])
That should do it! :)
If you write it in 2.5 there is a tool given with python 30 that will convert your code to python 30 code. But it still wont stop issues such as wxPython not having a python 30 module
Yeah, i know what you mean scru. I was using this because of the relatively simple lists. But thanks for the heads up. I love learning of new modules :)
You should also know that python has a powerful (though somewhat cumbersome) ctypes library that allows you to call C functions. This will handle your last request if you don't find a different built-in method of doing it (you may have to call the underlying platform's libraries to get the pictures).
Yeah good one i really didn't think of that. Here is a site where they did that, so i guess if you download the code then maybe you could get it to work. But im really not much of an expert on Ctypes
Oh i did exactly the same exercise myself when learning about lists, what you need to know here is about the "in" keyword. It is used to check if "a in b" so what we can do is check if item a is in list b. If it is then we have a match. Get it? I hope so. If not here is an example:
def getMatches(first, second):
count = 0
for item in first:
if item in second:
count += 1
return count
list1 = ['spam', 'eggs', 'bacon',"ham"]
list2 = ['spam', 'ham', 'king richard']
print "there are ",getMatches(list1, list2)," matches"
Hope that helps you on your way!
:)
5- can access a scanner and input pictures from it.
thankx in advance :)
Hey docsam,
"can access a scanner and input pictures from it"
I guess this is possible too, but never tried it on my own before.so have a nice time with python.
Mearah
Well i tried this a while ago, accessing a scanner. I count not find anything to do that with python. What i would do is use another program to get your images from a scanner and then process them with python.
cheers
Paul
Try using the absolute path, such as
"C:\\Documents and Settings\\Paul\\Desktop\\Programming\\Excel\\values.xls"
Remember that the double backslash is used so there are no escape characters such as \n used accidentally. There is a way to get around that and that is putting an r in front of the first " sign. That formats it into a raw string and escape characters are ignored.
Yeah you can do open internet things with the webbrowser module.
Oh and also execfile is good if you want to start executables or python files.
>>> import webbrowser
>>> webbrowser.open("www.google.com")
And execfile
#its a built in!
execfile("Path \\ to\\ exe or py \\ file.exe")
Hope that helps
ok well im looping to find a specific detail, but there are like 5 specific detail to find. When I do my while loop i keep getting the first one only how do i make it jump to the next one and store the other detail?
Okay, a tad more confusing then it was before. What do you mean? Can you just us some pseudocode. Something that will outline what you mean cause i dont understand what you mean by the specific detail bit at all, or any bit really. :P
If you just re-installed python you might have installed python 30 which means that you now have to go
print("hello")
See if that fixes it. :)
You cant just get a value from a button, buttons are basically used to call events and such, so you would need some kind of text entry and then when the button event was called use the assert keyword.
Assert is a keyword that raises an error if its requirements are not met.
http://www.rexx.com/~dkuhlman/python_101/python_101.html#SECTION004330000000000000000
Here is an example
#python 2.x code
i = int(raw_input("Enter the number 10"))
assert i == 10, "Error i does not equal 10"
HTH
Well firstly you were close with the code tags. It goes
[code=python]
[/code]
But if that is your full code then there are a couple of things that you need to do.
The first of which is instantiate it. This means that you have to create an instance of it. You do that by going like this:
c = circle()
Cool so not you have an instance the __init__ method will have been called (it is called the first time you instantiate the class) and now you can call the draw method:
c.draw(20,20)
c.draw(30,3)
So add those three lines of code to the end of your program and have a fiddle around with the minor details to get it better.
Hope that helps.
Yeah cheers, i think i get it all now. A little weird to bend my head around but ill get there. Thanks for your help.
That's because you're including the file "menu.h" ...
In 'menu.h' the whole class is declared so the compiler knows about it ...BTW, While compiling the compiler will put all these files together to one file: the object file ...
Ah i didnt see that one file, so basically the compiler notices that I use the class as a sort of abstract class. Then it makes it into one object and when you call SimpleMenu from menu.h SimpleMenu has all the attributes that menu.cpp made for it.
I hope that right. :)
So does that mean if i renamed the cpp file something apart from menu.cpp it wouldnt work or am i completley on the wrong foot here?
Hi,
I have been exploring doing some GUI programming with the wxWidgets toolkit as i am used to that from programming wxPython in python. I am doing the tutorials from zetcode and i am very mystified. (i think i spelt that wrong). This is the url http://zetcode.com/tutorials/wxwidgetstutorial/menustoolbars/ Its the first one on the page.
The issue i am having difficulty grasping is to do with the way that menu.h and menu.cpp work together because nothing ever seems to ever deal with menu.cpp yet it still defines the constructor and other functions. My questions is, how does it know to go to that file for the constructor? Or is that just all done when compiling, im just really confused as to why nothing is getting done to menu.cpp, its all menu.h that is getting included.
Cheers
Yes, zipfile=None is important if you just want one exe file with everything in it! Haven't totally tested the code, so you are my labrat.
Well i tried it and it worked fine. Probably the best setup script i have come across, thanks vega.
Well then i would have a look at wxStaticBitmap, that will handle your images no worries, then you can look at wx.Media.MediaControl for playing your files. Then you just have to bind the buttons in the usual way.
wx.StaticBitmap
http://www.wxpython.org/docs/api/wx.StaticBitmap-class.html
wx.Media.MediaCtrl
http://www.wxpython.org/docs/api/wx.media.MediaCtrl-class.html
I wrote tutorials on how to use both of them, find them at: http://wxpython.webs.com/tutorials.htm Take a look at tutorial 5 and 6
So something like, if you did post that day, on average how many posts do you do on a day that you are online?
LOL I didn't think you guys liked it so much! I just thought it was a completely useless statistic that came with vBulletin by default. I'll consider putting it back :)
Oh goody! I like it, i just find it interesting to see how actively someone contributes to the site, whether they are an active member and post a load, or if the just post every now and then.
Well cause i liked it so much i just put together a quick python script to do it for me:
from datetime import date
#get number of posts
posts = input("Please enter your posts: ")
#!!! Change date to your join date (y,m,d) !!!
joindate = date(2008,5,6)
#the date today
now = date.today()
#get another date object..
daysInDateForm = now-joindate
#and do the maths
print "Your posts/day = %0.2f"%((posts*1.0)/daysInDateForm.days)
Well hopefully you guys can use it if you need.. its still not quite the same as having it on your page. But oh well.
Yeah i agree AD. I tried to work it out and it took about 6 or so minutes adding all the months' days together. Its going to be even longer for you. :(
Hmm i think i see what you are doing, personally what i would do is make a python program that made an actor and then pickled it rather then using what you are doing, that way you could unpickle it in the actor class and everything would be fine and dandy.
But its all up to you, i think its going to be quite hard that way.... unless you want to use something like eval() to make a dictionary.. that might just work..