jlm699 320 Veteran Poster

cPickle.dump(pickleFile, lst)

help(cPickle.dump)
Help on built-in function dump in module cPickle:

dump(...)
    dump(obj, file, protocol=0) -- Write an object in pickle format to the given file.
    
    See the Pickler docstring for the meaning of optional argument proto.

Looks like the order's backwards... try instead: cPickle.dump(lst, pickleFile)

scru commented: didn't test that one +6
jlm699 320 Veteran Poster

This was the first result from googling "ubuntu install pygame": http://www.pygame.org/wiki/kubuntu

One of the best things about Ubuntu(Linux in general) is that it has such a huge open-source user base that almost every question you have has a detailed guide online of how somebody else did it.

sneekula commented: thanks +6
jlm699 320 Veteran Poster

Sure, we can help! Just remember to follow the forum rules, and pay attention to the posted announcements (here and here), and there won't be any problems.

This post by vegaseat should get you started...

Nick Evan commented: That'll do +16
jlm699 320 Veteran Poster

say you have list a = [2,4,6,8,10]
and list b = [2,6,10,12]

is there any way to make a list c show all the ones they have in common? so list c = [2,6,10] ?

Use sets and then convert back to list and sort() to get it ordered.

>>> setA = set([2,4,6,8,10])
>>> setB = set([2,6,10,12])
>>> rtn = list(setA.intersection(setB))
>>> rtn.sort()
>>> rtn
[2, 6, 10]
>>>

HTH

jlm699 320 Veteran Poster

so this will be about as simple as you can make a loop:

def main():
    print ("I'm the main function!")
    main()

main()

That isn't ideal as you're making it a recursive function. I think this would be the easiest way to make a loop:

def main():
    print ( "I'm the main function!" )

while True:
    main()

You could also dictate a particular number of times to run the main function like this with a for loop:

def main():
    print ( "I'm the main function!" )

num_loops = 15
for i in range( num_loops ):
    main()
jlm699 320 Veteran Poster

not quite sure what the difference with int(raw_input) is from just input, but i'll figure it out...i notice command is in 2.6, but not in 3.0

raw_input forces the user's input into a string data type, where as input actually parses the input... this should illustrate the difference:

>>> input( "Enter something: " )
Enter something: 4 + 7 * 10
74
>>> raw_input( "Enter the same thing: " )
Enter the same thing: 4 + 7 * 10
'4 + 7 * 10'
>>>

As you can imagine, it would be possible to enter malicious code using this method.

In 3.0 this "hole" was closed by making input() the new raw_input() and doing away with the parsing method... I hope that wasn't too confusing I know I didn't explain it well.

Check this out: it's Python Regrets, a good read.

max.yevs commented: ah alright nice +1
jlm699 320 Veteran Poster

Each tuple in that list has an instance of scrobble.Track, which contains an instance of scrobble.Artist; however the tuple itself does not have those attributes.

I'm not entirely sure on the specifics of the scrobble module, but a way to unpack the tuple would be like this:

for tracks in recent:
  track_info, track_date = tracks
  print track_info

Perhaps the scrobble.Track class has a built-in __repr__ overload so that printing the object itself will result in 'Groove Armada' - 'Hands of Time' instead of <scrobble.Track(<scrobble.Artist(u'Groove Armada') - u'Hands of Time') Although, perhaps once you have that tuple unpacked you can use something like track_info.Artist .. I guess it will take a little experimenting

jlm699 320 Veteran Poster

"cross platform (windows + linux)"
This is possible. What you have to keep in mind, that if you are creating some GUI (with TkInter e.g) then it looks quite differentwith windows and linux, so you maybe could test the "look&feel" of your work with both os

I'd go with wxPython for the GUI, as it's already designed with cross-platform apps in mind. The GUI that you create appears native to any system that the app is run on.

I've used it before for cross-platform GUIs and they've all turned out to be beautiful on all the platforms that I tested (win, *nix)

scru commented: our ideas of "beautiful" are very different. +6
jlm699 320 Veteran Poster

google is your friend http://commons.wikimedia.org/wiki/File:Dragon_curve.png

Wow. I love that db replaced the text within that hyperlink with a smiley. I'm sorry this post isn't on topic but I just wanted to get that out there.

Hey, and the link still works!

EDIT:
kette = chain
laenge = length
zeichne = draw
* Courtesy Google Translate

jlm699 320 Veteran Poster

Another great little trick for classes is providing a __repr__ method, so that when you print the object of a set, instead of displaying a message like this:

>>> class my_class(object):
...     def __init__(self):
...         self.A = '1'
...     
>>> mc = my_class()
>>> mc
<__main__.my_class object at 0x01D24BF0>
>>>

You get this:

>>> class my_class(object):
...     def __init__(self):
...         self.A = '1'
...     def __repr__(self):
...         return 'Hi, my A value is currently %s' % self.A
...     
>>> mc = my_class()
>>> mc
Hi, my A value is currently 1
>>>

Keep in mind that you can make the return value of your repr() function literally anything. It's completely up to you how you want your class object represented.

sneekula commented: good explanation +6
jlm699 320 Veteran Poster

First of all, you should use code tags like such:
[code=python] # Code goes in here

[/code]
Which would've given you the following:

if param[0:4]<>'ini=':
    print ' %s ini='%sys.argv[0]
    sys.exit(1)
inifile=param[4:]

Now, to answer your question:
First we check that the first 4 characters of param are "not equal" to ini= ... <> is the obsoleted form of != So, as long as the first four characters of param are not 'ini=' then we execute the code block within the if statement, which is printing the name of our program ( sys.argv[0] is always the name of the running program), and then we exit with a return of 1...

If the first four characters of param WERE 'ini=', then we would execute the line of code immediately after the if block, which declares the variable inifile to be equal to the remainder of param.. here's an example of that slicing:

>>> param = 'ini=myinifile.txt'
>>> param[0:4]
'ini='
>>> param[:4]
'ini='
>>> param[4:]
'myinifile.txt'
>>>
vegaseat commented: very nice +11
jlm699 320 Veteran Poster

I need help with my homework :( but no one's replying. [note: this comment was just to move this thread back to the top of the list]

This isn't a place to come and have your homework done for you. Forum-goers here typically don't just give out solutions to homework, as that would be immoral and you'd never learn anything.

When it comes to homework or projects the best bet for getting help is to give us the code that you've tried and the errors or incorrect results that it has produced. We can then give you tips and help you tweak the code, but we do not provide e2e solutions. Not for homework, anyway... I suggest reading this announcement

Oh and we know what a *bump* is; no need to explain.

jlm699 320 Veteran Poster

You would want to initialize the counter to 0 before your while loop like my_count = 0 and then near the end of the loop contents you can add a my_count += 1 (which is equivalent to my_count = my_count + 1 )

eyewirejets commented: Soved it easily +1
jlm699 320 Veteran Poster
def printGrid(self):
        for y in range(self.height):
            for x in range(self.width):
                print self[x, y].value,
            print

	def printGrid2(self):
		for y in range(self.height):
			for x in range(self.width):
				print self[x, y].value,
			print

the printGrid2 method can't be found or something.

Indentation is very important in Python. Your printGrid2 method is defined within printGrid, so it isn't a member of the class Grid

This should fix it:

def printGrid(self):
        for y in range(self.height):
            for x in range(self.width):
                print self[x, y].value,
                print

    def printGrid2(self):
        for y in range(self.height):
            for x in range(self.width):
                print self[x, y].value,
                print

It appears that you're using a mix of tabs and spaces, which is a no-no. Save yourself the trouble and convert all your tabs to spaces (4)

jlm699 320 Veteran Poster

Is that chat speak or did he get disemvoweled ?

Ezzaral commented: :) +16
jlm699 320 Veteran Poster

How about you show us what you've tried and we'll help you. That's how it's supposed to work, we're not here to do your homework.

And when you're posting code please use code tags:
[code=python] # Code in here

[/code]
When you do that you can make code that looks like this:

import os
#
if os.path.exists('/home/user/friends'):
    print 'Nice!  Friends!!'

See how nice that looks?

vegaseat commented: thanks for the code tag info +11
jlm699 320 Veteran Poster

What's a search engine?

The best part is that two people didn't pick up on the sarcasm and actually replied. Makes this triple-funny

Salem commented: *bows* +26
jlm699 320 Veteran Poster

hoe to write a generic code for creating a empty 2D array and dynamically insert values in it.

>>> arr_2d = [[]]
>>> arr_2d[0].append(0)
>>> arr_2d[0].append(1)
>>> arr_2d.append([3,4,5])
>>> arr_2d
[[0, 1], [3, 4, 5]]
>>>

It might benefit you to create a 2d array class to handle the many different aspects of working with a 2d array.

vegaseat commented: as dynamic as it gets, good example +11
educapps commented: Great logic! +0
jlm699 320 Veteran Poster
screen.blit(image, (10,10))

I think..

vegaseat commented: great help +11
jlm699 320 Veteran Poster

Your loop starting on line 129 is only one line long (130)

AKA, infinite loop:

while 1:
        clock.tick(60)
jlm699 320 Veteran Poster

Are you by chance running the program as admin? I think that other Vista users on this forum have been bitten by this problem. If you right-click on the program I think there's an option to "Run as admin" or similar (I don't have Vista so I have no idea).

This has helped others, maybe it can help you too, although since the program itself isn't an executable perhaps you need to be running python as admin. I'm not sure.. let me know whether this option exists for you or not.

ihatehippies commented: helpful +1
jlm699 320 Veteran Poster
>>> import random
>>> my_seq = ''.join([random.choice('AGTC') for x in range(10)])
>>> my_seq
'TATCCTTGTT'
>>> len(my_seq)
10
>>>

I'm not quite sure what you mean by "printing in FASTA format with the > "

jlm699 320 Veteran Poster

(I think (I) (Might) ((See) A Problem) (Here)

This is improper syntax, you're missing a closing parenthesis ;)

No but seriously, to the OP: the error you are getting is trying to tell you that the image file that you're trying to open doesn't exist. You need to check your current working directory during runtime and verify that the file is located within the same directory

import os

os.getcwd()

If it is not, you'll need to provide the entire path to the file name in order to use it. That or change your current working directory. And yes, it looks like perhaps having those parenthesis around your assignment might have something to do with it.

tyincali commented: Why didn't I catch this... +1
jlm699 320 Veteran Poster

Wow turtle is fun to play with :)

import turtle, time

tp = turtle.Pen()
tp.color('blue')

for k in xrange(51):
    for j in xrange(k):
        tp.right(360/float(k))
        tp.forward(25)

time.sleep(3)

*Oops I didn't mean to post this here, it was supposed to be in the thread asking about turtle *sorry*

Editor's note: It's okay, we leave it here as an examle of good thinking.

jlm699 320 Veteran Poster

Refer to this post

jlm699 320 Veteran Poster

I did this and had a hell of a time figuring it out!

Go to Run -> "Run...", then type in C:\PythonXX\pythonw.exe "$(FULL_CURRENT_PATH)" ** Note I use pythonw.exe, you can just as easily use the standard python.exe (I just hate that console window), and when you've got that hit the "Save..." button for a dialog where you can name it and assign a shortcut to it.

*Note: Ctrl + R was already taken (and I'm too used to it from CodeEditor) so I went to Settings -> "Shortcut Mapper..." to give my python run command the Ctrl + R and moved whatever that used to be occupied to something else

Just dug this out of my bookmarks: Notepad++ Run external tools

jlm699 320 Veteran Poster

you need to use the file handle and not the loaded object when you dump. You should just reopen the file for reading or writing and not worry about a+.

#User Access for Password.py
import cPickle as p
import sys

my_file = 'systemaccess.txt'
file_handle = open( my_file, 'r' )
temp = p.load( file_handle )
file_handle.close()

def EP(self):
    if self.lower() == 'exit':
        print 'Exiting Program.'
        sys.exit()
        
print 'Welcome to the System Account Setup.'
print 'Enter Exit to end the program at any time.'
Username = raw_input('Please enter the username you desire: ')
EP(Username.lower())
Password = raw_input('Enter your desired password: ')
EP(Password.lower())

if Username.lower() in temp:
    print 'That username already exists.'
else:
    temp[Username.lower()] = Password.lower()
    file_handle = open( my_file, 'w' )
    p.dump(temp, file_handle)
    file_handle.close()
jlm699 320 Veteran Poster

An even easier workaround for being able to import modules from ANY directory is to modify the sys.path variable at run time. So at the beginning of your code do something like this:

import os,sys
sys.path.append('/path/to_my/module')
import my_custom_module

And if you're working with a hard-coded windows path make sure you escape your escape characters (ie, C:\\Documents and Settings\\Administrator\\My Documents )

A better way to handle paths is using os.path.join()

>>> import os
>>> os.path.join('C:\\', 'Documents and Settings', 'Administrator', 'My Documents')
'C:\\Documents and Settings\\Administrator\\My Documents'
>>>
jlm699 320 Veteran Poster

I don't know; as I've never used it. If that does not suit your needs you'll possibly need to look into the Excel API; which can be access via win32com (you'll need to learn how to use COM objects).

tzushky commented: Thanks +1
jlm699 320 Veteran Poster

I don't know how that is not giving you any errors. There is no indentation and you're missing the %s %s after the cp command on the last line.

vegaseat commented: Nice help +8
jlm699 320 Veteran Poster

When using psycopg2 your operations are only transactions. In order to get your transaction to commit to the database you'll need to issue a conn.commit() command.

PoovenM commented: AWw man you're brilliant :D +2
jlm699 320 Veteran Poster

There are a few possibilities I can think of, but probably the most straight forward:

>>> li = [ 1, 2.3, 4e-5, 'hey!' ]
>>> for item in li:
...     test = str(item)
...     if test == item:
...         print item, 'String!'
...     else:
...         print item, 'Not String!'
...     
1 Not String!
2.3 Not String!
4e-005 Not String!
hey! String!
>>>

Now when you say restrict this to positive numbers, do you mean:
If Input is not <a positive number>:
perform action

vegaseat commented: Good example +8