lllllIllIlllI 178 Veteran Poster

To help get a bit of more publicity on things like the IRC or code tags and other things, it would be nice to have a little tutorial or something that a new user had to go through before they properly joined the community.

That way we could get the word out about this and also get it so people actually understand code tags before they go out into the forums.

:) just thinking

lllllIllIlllI 178 Veteran Poster

hahaha, ill should be able to help up to a point :) Im not that familiar with these libraries.

Hope i can help :)

lllllIllIlllI 178 Veteran Poster

Yeah i did this just a little while ago myself. Here is the tutorial i used for it:
http://kutuma.blogspot.com/2007/08/sending-emails-via-gmail-with-python.html
That will work with gmail :)

lllllIllIlllI 178 Veteran Poster

ooh my bad :S.

lllllIllIlllI 178 Veteran Poster

Ah the life of a mod sounds like so much fun :P if all you do is delete bad posts!

Im sure there is more to it then just that

lllllIllIlllI 178 Veteran Poster

i'll see you there :)

lllllIllIlllI 178 Veteran Poster

I have been using daniweb for about a year and a half now, starting out asking the questions on the Python forum, now i usually answer them. But i really just wanted to say thanks, i feel this is a really strong community and the moderation team does a great job.

All the bad posts seem to be taken care of quickly, flame wars are few and far between, and mostly the forums run nicely and everyone gets things done.

So, i guess im just saying thanks for all the help i have gotten over the year and a bit, and to everyone out there fore making such a great community. And hopefully my posting in the python forum is helping someone. :P

Well done guys :)

lllllIllIlllI 178 Veteran Poster
lllllIllIlllI 178 Veteran Poster

what i would do is read the whole file into one list, then you can do something like:

#open it, it is automatically in read mode
f = open("dnalookingfile.txt")

#get a list with all the lines
lines = f.readlines()

#iterate through the lines
for line in lines:
    if "rs" in line:
        #delete this one from the lines list and the next one as well
    else:
        #its all good, the line does not have rs numbers in it

Then you could just rewrite the file after you are done and it would be fixed :)

Hopefully :P

lllllIllIlllI 178 Veteran Poster

Yeah, i dont know if you may have checked this. But i know i stuffed this up one time, but are you sure its .jpeg not .jpg or .JPG or something like that?

:P

lllllIllIlllI 178 Veteran Poster
self.Bind(wx.EVT_MENU, self.Close(), id=ID_FILE_QUIT)

Theres ya problem!
You dont need to put the brackets after self.Close, the brackets are only used if you actually want to call the function, so take out those brackets and try again. That hopefully should fix your dilemma.

:)

lllllIllIlllI 178 Veteran Poster

I always use the wxPython api when i want to find something out, its a very very useful skill to be able to do that, because of the lack of documentation you really have to try and use what you do have.

I once wrote a small explanation on wxTextCtrl, ill attach it to the post, its a pdf. One bit of it goes over the side of the page, sorry bout that :P

Hope it helps

lllllIllIlllI 178 Veteran Poster

Yeah i agree, i think the best that you could do was boot into windows or something and then just start you new 'python OS' being a fullscreen gui that can do things that you want it to.
But as for an actual os, it is impossible as python isnt low-level enough and needs an interpreter.

lllllIllIlllI 178 Veteran Poster

It is used when using formatted strings.
I could try explain, but a great book has been written and has a bit about it :)
http://diveintopython.org/getting_to_know_python/formatting_strings.html

Read and enjoy the best free book on python imho

hope that helps

lllllIllIlllI 178 Veteran Poster

Well to start off with, it sounds pretty simple what you are doing, so just read this tutorial. It is a comprehensive way to start with python.
http://docs.python.org/tutorial/
Once you finish that you will be able to do everything but printing, that is a rather advanced thing to do with python. I think vegaseat may have done a code snippet that did something like that...

lllllIllIlllI 178 Veteran Poster
self.Bind(wx.EVT_BUTTON, self.UpdateNebula(), self.Update_Nebula)

This will not work, you are actually calling the fucntion self.UpdateNebula when you put the parentheses there, so if you get rid of them you will be fine :)

Another way i do it a lot is just to bind them to the objects themselves:

self.Update_Nebula.Bind(wx.EVT_LEFT_DOWN, self.UpdateNebula)
#this will bind it to the same as if you did the previous code, i just find it has less issues

But its really up to your own taste what you want to do.

lllllIllIlllI 178 Veteran Poster

Wow, thought I tried that.

Sorry.

Hahaha! Never apologise for a question, a stupid question is one that doesnt get asked :)

lllllIllIlllI 178 Veteran Poster

if you have a list its as simple as calling the sort() method

li  = ['a','h','w','j','s','r','y']
li.sort()
print li
lllllIllIlllI 178 Veteran Poster

Learn python
http://docs.python.org/tutorial/

Come back when you can do all that and ask a much more specific question

Nick Evan commented: Sounds like descent advice to me :) +19
lllllIllIlllI 178 Veteran Poster

Hold on, i just realised, its not one line... And i know python isnt about making things as small as possible. Its just i love the challenge of doing cool list comps :P

import random
print ''.join([random.choice('abcdefghjklmnopqrstuvwxyz!@#$%^&*') for g in range(8)])

Cause i can :)

P.s. Imports dont count!

lllllIllIlllI 178 Veteran Poster

I would basically put all of this in the main function.

load = RockPaperScissors(3, 0)   	
#3 is the number of tries to star with, 0 is the number of points
output_rand = load.random()             
output_decision = load.decision(output_rand)         
output_score =load.score(output_decision)            
output_exit = load.exit()


while condition == 'true':
	print '--------------------------' '\n'
	load = RockPaperScissors(output_exit, output_score)
	output_rand = load.random()             
	output_decision = load.decision(output_rand)            
	output_score =load.score(output_decision)  
	output_exit = load.exit()

So then it will look like this:

def main()
    load = RockPaperScissors(3, 0)   	
    #3 is the number of tries to star with, 0 is the number of points
    output_rand = load.random()             
    output_decision = load.decision(output_rand)         
    output_score =load.score(output_decision)            
    output_exit = load.exit()


    while condition == 'true':
            print '--------------------------' '\n'
            load = RockPaperScissors(output_exit, output_score)
            output_rand = load.random()             
            output_decision = load.decision(output_rand)            
            output_score =load.score(output_decision)  
            output_exit = load.exit()

And then we can add in out exit condition.

def main()
    load = RockPaperScissors(3, 0)   	
    #3 is the number of tries to star with, 0 is the number of points
    output_rand = load.random()             
    output_decision = load.decision(output_rand)         
    output_score =load.score(output_decision)            
    output_exit = load.exit()


    while condition == 'true':
            print '--------------------------' '\n'
            load = RockPaperScissors(output_exit, output_score)
            output_rand = load.random()             
            output_decision = load.decision(output_rand)            
            output_score =load.score(output_decision)  
            output_exit = load.exit()
            if output_exit == False:
                return

And that will work if you have changed the exit function to the one i outlined above.

Hope that helps:)

lllllIllIlllI 178 Veteran Poster

Just a quick note. The above code will work if you change all of the instances of "sys" to "os"

SO it will look like

import os
os.system("shutdown -s")

Hope that helps :)

lllllIllIlllI 178 Veteran Poster

Hahaha, for things like this, i always try and do list comprehensions and get it down to one line, that is not including any of the import statements.

I got this

import random
values = 'abcdefghjklmnopqrstuvwxyz!@#$%^&*'
print ''.join([random.choice(value) for g in range(8)])

So what that does is it uses list comp to get a random letter from the values variable. it does this eight times, as many as are in the range. Then once that is done using the join function i join all of the list together into one simple eight digit long string ready for printing or storing as a variable!

Hope that helps, or is slightly interesting :P

lllllIllIlllI 178 Veteran Poster

I dont know if its just me, but that dosent quite make that much sense. Just spend a little more time outlining exactly what you actually want, what your problem is. What you have already tried.

Then we will be much better at helping :)

lllllIllIlllI 178 Veteran Poster

Yeah, there is another way

def exit(self):
		if self.tries == 0:
			condition = 'false'		
			print 'GAME OVER-'
			return False

		remaining_tries = self.tries
                return remaining_tries

Then just put this at the end of the Main function

if output_exit == False:
    return

That way, when it returns false the main function exits. The program will then end because there is no code left :)

Hope that helps.

lllllIllIlllI 178 Veteran Poster

Also, when i import things i get a syntax error if i have brackets in my import. So that might be it, seeing as it looks like its trying to import
NumberStimuliGenerator(revised). Personally i would change the file's name to something without brackets. Seeing as in python, they usually mean a tuple or function!

Hope that helps

lllllIllIlllI 178 Veteran Poster

Yeah i used to go a flash game site but then they got ads that just constantly talked. And it was annoying to turn off my whole sound just to play something. So eventually i just stopped going there. Im pretty against anything i dont like having access to my speakers :)

lllllIllIlllI 178 Veteran Poster

lol. i didn't realize til today that the tutorials i've been watching are paulthom's tutorials. thanks!

Oh God, those things. They are so embarrassing, not the content so much as my voice, they were all done just before my voice broke. So i am a puny little kid it sounds :$

lllllIllIlllI 178 Veteran Poster

I use the Chrome Beta and that works a charm.

lllllIllIlllI 178 Veteran Poster

Wow, i must say i am impressed. A lot of people just sit around lazily for answers, its great that your pursuing them yourself. It will certainly lead to you learning a lot faster ;)

lllllIllIlllI 178 Veteran Poster

Then you will probably use something called recursion.
That is when a function calls itself. It is used in these kind of situations.

def recurse(num,count):
    if count == 10:
        return
    else:
        print num/2
        recurse(num/2, count+1)

recurse(100.0,1)

See, the recursive function has something called a base case. That is something that the recursive function knows what to do with and can stop recursing. So in this case our base case is that if the count is equal to ten then the function will return, therefore returning to the previous function. That in turn returns to the function it was called from up till the top one. But if it does not match the base case we print our new result and continue with recursion.

Hope that helps

EDIT: I made it 100.0 so that it would use decimal places where necessary.

sneekula commented: nice example +8
lllllIllIlllI 178 Veteran Poster

Showing images is easy with wx.StaticBitmap.
http://www.wxpython.org/docs/api/wx.StaticBitmap-class.html

NOTE:This code is borrowed from the sticky

# show  .jpg .png .bmp or .gif image on wx.Panel

import wx

class ImagePanel(wx.Panel):
  """ create the panel and put image on it """
  def __init__(self, parent, id):
    # create the panel, this will be self
    wx.Panel.__init__(self, parent, id)
    try:
        # pick your image file you have in the working folder
        # or use the full file path
        image_file = 'strawberry.jpg'
        bmp = wx.Bitmap(image_file)
        # show the bitmap, image's upper left corner anchors
        # at panel coordinates (5, 5), default is center
        wx.StaticBitmap(self, -1, bmp, (5, 5))
        # show some image information
        info = "%s  %dx%d" % (image_file, bmp.GetWidth(), bmp.GetHeight())
        # the parent is the frame 
        parent.SetTitle(info)
    except IOError:
        print "Image file %s not found" % imageFile
        raise SystemExit


# redirect=False sends stdout/stderr to the console window
# redirect=True sends stdout/stderr to a wx popup window (default) 
app = wx.App(redirect=False)
# create window/frame, no parent, -1 is the default ID
# also increase the size of the frame for larger images
frame = wx.Frame(None, -1, size = (480, 320))
# create the panel instance
imp = ImagePanel(frame, -1)
# show the frame
frame.Show(True)
# start the GUI event loop
app.MainLoop()

Hope that helps

lllllIllIlllI 178 Veteran Poster

Yeah they do, but what i do is usually find out what i need to use with the demo. Fiddle around a little bit with the declaration of the object i am using just to get a little used to it. Then i look at the api, i find that is the best learning tool for wxPython, you just have to try a little sometimes. :)

lllllIllIlllI 178 Veteran Poster

I suggest downloading the 'Docs and Demos' along with your wxPython install, as it gives you a great launch pad to start writing your own GUIs by giving you sample code of almost every single type of wx object.

It's ridiculously helpful when starting wxPython.

That is in fact a great idea, that and the api are powerful learning tools.

lllllIllIlllI 178 Veteran Poster

Okay, thats simple enough. What you would be looking at is using wx.StaticText for all of your displaying text needs.
http://www.wxpython.org/docs/api/wx.StaticText-class.html
This you can update with the SetValue("Value") function.

If you ever need user input you can use wx.Button
http://www.wxpython.org/docs/api/wx.Button-class.html

Or a wx.TextCtrl, this is basically like an input box. Kinda like the one you type your forum responses into.
You can get its data by using the GetValue() function
http://www.wxpython.org/docs/api/wx.TextCtrl-class.html

Hope that helps you on your way :)

lllllIllIlllI 178 Veteran Poster

Well here is some code that will raise that error

>>> l = None
>>> l[0]

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    l[0]
TypeError: 'NoneType' object is unsubscriptable
>>>

Now what that error means is that you have something of NoneType, literally it has a value of None, then you try and use the square brackets like you do in a list. But if it is a nonetype it is "unscriptable" so therefore will raise that error.

If you post the code, it would be easier to be more specific.

lllllIllIlllI 178 Veteran Poster

Yeah its not too hard to find the size.. There isnt a function but when you open an image it stores it in the size variable.

So

from PIL import Image

f = Image.open("10x.png")
print f.size

Hope that helps

lllllIllIlllI 178 Veteran Poster

The second one is a simple funciton

#our list
l = ['Hello','world','from','python']

#use the join() function to join the words together with spaces
string_list = ' '.join(l)
print string_list
#prints
#Hello world from python

Im pretty sure that changed for python 30. Im not how you do it there

lllllIllIlllI 178 Veteran Poster

I was just wanting to tell you (cscgal) that i was unable to access the site for about 3 hours last night (Australian Time). I kept getting a database error, it asked me to refresh or email you guys.

I couldn't get to any part of the site at all, none of the forums or just the homepage.

Cheers
Paul

lllllIllIlllI 178 Veteran Poster

os.makedirs is a really useful function. It makes all of the path that you give it. So if you gave it the path C:\Python\Test\one\two you dont already have to have the path Python, Test, one or two. This is better then os.mkdir because that doesn't work unless you have the full path except the one you want to create. So in that case you would need C:\Python\Test\one and two would be the one created.

import os

#Firstly we make the folder path.
os.makedirs("C:\Python\Storing\a\Text\File\)
#then we change the directory that python looks at to the new place.
os.chdir("C:\Python\Storing\a\Text\File)

#and because we changed the directory we can just go
f = open("File.txt",'w')
#rather then open("C:\Python\Storing\a\Text\File\file.txt",'w')

#write to the text file
f.write("Hello world")

#and close it
f.close()

Hope that helps

lllllIllIlllI 178 Veteran Poster

Yeah, i get this a lot with wxPython. Something on the lines of
wx.App must be created first. And IDLE will not freeze, but it will not run the code again until you restart it.

lllllIllIlllI 178 Veteran Poster

Hi All,

I have created a grid and want to implement the following idea:
The user should be able to enter only numeric values in any of the cells in that grid.

I could not get any property of the cell which can check for the entered data.

Please guide as for achieving this.

Thanks,
Dinil

Look, dinilkarun. This is not the first time you have provided to little information. If you want answers that help you really need to put in the effort. What is this grid? Is it in wxPython, Tkinker, pyQT or something? Cause unless we know that we cant do anything.

Try harder and you'll find it pays off in better answers

lllllIllIlllI 178 Veteran Poster

So what are the chances of starting a pyQT or pyGTK thread like the wxPython thread we have... sticky and all! I'd love to see some examples of either pyQT or pyGTK as I've no experience with either...

Thoughts?

Yeah i would like to see that as well. And if it is so complicated to install as Vega says then have things like how to install it on different OS's.
But im all for it. :)

lllllIllIlllI 178 Veteran Poster

To get the average i usually make a function

import random

def averageList(l):
    total = 0 
    for item in l:
        total += item
    return total/len(l)

#then i make my list
l = [random.rangrange(0,100) for f in range(100)]
print averageList(l)

Functions are a great way to reuse your code if you ever need to.

Hope that helps :)

lllllIllIlllI 178 Veteran Poster

Okay, start simple and understand what raw_input and input actually do:

raw_input([prompt])ΒΆ

If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised. Example:

>>> s = raw_input('--> ')
--> Monty Python's Flying Circus
>>> s
"Monty Python's Flying Circus"

If the readline module was loaded, then raw_input() will use it to provide elaborate line editing and history features.

Then understand lists:
http://docs.python.org/tutorial/datastructures.html

And then have another go at the problem, if you have any specific questions feel free to ask. But first try learn a bit more about what things do.

lllllIllIlllI 178 Veteran Poster

oh ok my bad but i still cant get it to work

Well show us your changed code so we can have a look at it then.

lllllIllIlllI 178 Veteran Poster

You can also request a free ubuntu CD be shipped to you, no shipping fees or anything. I used to use that when i had dialup internet :).

https://shipit.ubuntu.com/

Hope that helps!

lllllIllIlllI 178 Veteran Poster

I did something exactly like this when learning python. I would get the rain radar and the forecast for numerous places. The way i did this was i would download an image from the Bureau of Meteorology in Australia, then i would download the webpage with my forecast on it, scrape away all the tags and then i would get the text i wanted from that.

So www.bom.gov.au works if your in Australia. Not sure about other places, but im sure that there would be something readily available.

lllllIllIlllI 178 Veteran Poster
print "test test test"
lllllIllIlllI 178 Veteran Poster

PS. What's the Python code tag? When I call (code=python) I don't get the formating or syntax highlighting.

Yeah thats an issue right now. http://daniweb.com/forums/thread189444.html