jlm699 320 Veteran Poster

Does the *thing* have to be the source of the emitted vibration? I mean... any object could emit vibration if you consider reflected light as being emitted vibration.

And a Dr. Pepper can will emit vibration if you squeeze it. The crinkling aluminum produces the vibration of sound waves.

jlm699 320 Veteran Poster

What are old C/C++ programmers supposed to do then ? :(

Learn Python ;)

jlm699 320 Veteran Poster

A quicker way would be to check if a split() results in a list with length greater than 1:

>>> s1 = 'Test string'
>>> s2 = 'Test'
>>> s1.split()
['Test', 'string']
>>> s2.split()
['Test']
>>> len(s1.split())
2
>>> len(s2.split())
1
>>>

On second thought, it'd be easier to just do a direct check like this:

>>> def check4space( s ):
...     """ Checks for spaces in the input string s
...         returns True or False """
...     return ' ' in s
...     
>>> check4space( 'This is a test string' )
True
>>> check4space( 'Foobar' )
False
>>> check4space( '13457890)(*&^%$#@!' )
False
>>>
jlm699 320 Veteran Poster

Thanks for the replies but I get forbidden page everytime when i try to go to my address with additional variables in slashes. I assume there should be some .htaccess setting for the server to be able to divide the url into the "actual url" and the variables.
More of a server issue i suppose, any1 had experience with this? :)

Let me get this straight... you're trying to access this page: http://host.com/script , and pass these as variables: 2008/05/05 ??

I guess my question to you is: why? I'm certainly not an expert on the subject, but I'm pretty sure it will never work like that... why don't you just use POST/GET or some other similar manner to pass your variables? If you need help on passing variables in HTML just google "HTML pass variable" and you'll get plenty of answers.

jlm699 320 Veteran Poster

Write an empty string to them, a.k.a. '' That's the best answer you could hope for with as little info as you provided.

jlm699 320 Veteran Poster

How about you use __init__.py in each of your subdirectories? Here's an illustration of the __init__.py idea from an old mailing list:

__init__.py is used for two things. One is as a flag to
indicate that the python programs in the directory are
part of a module.

The other is as the module itself. Let's take a simple
example. Assume you have a directory named breakfast
which contains modules named spam.py, eggs.py,
toast.py and jam.py, and that the directory containing
breakfast is on the PYTHONPATH.

If it try to import spam.py by writing

import breakfast.spam

it won't work because the breakfast directory
doesn't contain an __init__.py file.

If I then add __init__.py to the breakfast directory,
the import will work, and the result will be *two*
modules loaded. The first module will be bound to
the identifier 'breakfast' in your module. It will be
completely empty except for the identifier 'spam'
which will have the spam module bound to it.

This means that if the spam module contains,
for example, an identifier named "vikings", then I
can refer to it as breakfast.spam.vikings.

The real kicker here is that when I say that the
first module will be completely empty, it's not
quite true. First, it will have some standard
identifiers that all modules have, and second
it will have anything you put …

jlm699 320 Veteran Poster

Holy crap no. Jython is the scourge of humanity, and in my opinion utter and complete garbage. I don't even know why it exists except to astound and bewilder. I used it once to make an application that could interface with Lotus Notes.

Every time I look back at that period in my life I get sick thinking about having to use Jython. Blech.

scru commented: ++++++++++++1 +6
jephthah commented: but how do you REALLY feel? +10
jlm699 320 Veteran Poster

If the script has access to the URL you could do something like:

>>> url_in = 'http://host.com/script/2008/05/05'
>>> match_text = 'script/'
>>> index = url_in.find(match_text) + len(match_text)
>>> url_in[index:].split('/')
['2008', '05', '05']
>>>

Is that kind of what you were looking for?

jlm699 320 Veteran Poster

What, you mean like this?

>>> def funA():
...     print 'A'
...     
>>> def funB():
...     print 'B'    
...     
>>> def funC():
...     print 'C'
...     
>>> my_tup = ( funA, funB, funC )
>>> for each_function in my_tup:
...     each_function()
...     
A
B
C
>>>
jlm699 320 Veteran Poster

Here's a way to only check against the last character (as a function):

>>> def remove_dups( word ):
...     """ Remove all adjacent duplicate letters """
...     new_word = word[0]
...     for c in word:
...         if c != new_word[-1]:
...             new_word += c
...     return new_word
...     
>>> remove_dups ( "This phhrasse hhhhhas mmuullttiippllee repeaters" )
'This phrase has multiple repeaters'
>>> remove_dups( "Apple" )
'Aple'
>>>
jlm699 320 Veteran Poster

I think the most straight forward resource is py2exe.

Here's a tutorial.

Also, if you search this forum, you'll find numerous examples.

jlm699 320 Veteran Poster

Please use code tags when posting code in this forum. If you don't, your code is excruciatingly hard to read and makes it less likely that forum members will answer your question.

To use code tags:
[code=python] # Put your code inside here

[/code]

Now regarding the 'main' module: there is no set way to do this in Python, as the language doesn't require you to use any specific structure; however the most common way that you'll see a 'main' function being represented is this:

import os

def main():
    """ This is the main function """
    pass

if __name__ == '__main__':
    main()

This convention is used most commonly to avoid certain code from running when importing from this module. Now, with that being said I'm not so convinced that an editor would force you to use that style (or any style for that matter). I think that your problem might be something entirely different.

Could you copy-paste the exact error that you're getting? Also, the subject of the thread mentions jython... Are you using jython or python?

jlm699 320 Veteran Poster

range(0, 1010, 10)

jlm699 320 Veteran Poster

I concur with Jice. In case you're simply asking us for suggestions of how to perform the same action with two different targets I would propose a for loop:

>>> for octet in [ '8', '9' ]:
...     ip_add = '10.0.2.' + octet
...     print 'IP Address:', ip_add
...     
IP Address: 10.0.2.8
IP Address: 10.0.2.9
>>>

An even better solution would be to come up with a function that connects to a database and returns the connection object. The input to this function would be host information, login details, etc.

HTH

jlm699 320 Veteran Poster

Didn't notice the double post. Shame on you, shame on me...

jlm699 320 Veteran Poster

i only get a segfault without any output.
What is wrong??

Your C program is most likely at fault. Simply recode it in Python instead of just calling it from Python.

jlm699 320 Veteran Poster

Use .py instead of .pyw, as .pyw hides the console. .pyw are ran with pythonw.exe, whereas .py are ran with python.exe

jlm699 320 Veteran Poster

How about you use a dictionary for usrlst. here's an example of a dictionary:

>>> usr_dict = { 'bob': 'foobar', 'joe': 'barfood', 'sally':'choco' }
>>> usr_inp = 'Bob'
>>> if usr_inp.lower() in usr_dict:
...     print usr_dict[usr_inp.lower()]
...     
foobar
>>>

Also, you should not be using input , you should be using raw_input

jlm699 320 Veteran Poster

Search this forum or google for subprocess. It's the new de facto method of spawning processes. There's plenty of examples if you look.

jlm699 320 Veteran Poster

Here's a clue:

>>> for x in xrange(0, len(msg), 2):
...     print msg[x], msg[ x + 1 ]
...     
 5 8
18 7
>>>
jlm699 320 Veteran Poster

This is pretty straight forward:

>>> my_dict = {}
>>> for item in str1.split(','):
...     key,value = item.split(':')
...     if my_dict.get( key ):
...         my_dict[ key ] += int( value )
...     else:
...         my_dict[ key ] = int( value )
...     
>>> my_dict
{'a': 3, 'c': 4, 'b': 3}
>>>

If there's any piece that you don't understand.. ask and I'll explain

jlm699 320 Veteran Poster

It's 2.6 but it works now. I just restarted IDLE and it worked. BTW, anyone have a suggestion for a better IDE?

I use Notepad ++ and set it up to be able to run my Python programs, verify their syntax and launch the PyCrust shell...

I highly recommend it.

jlm699 320 Veteran Poster

No, you should never be declaring classes inside a function... Your class definitions should go out on the main level and then call them from within the functions...

Also, get rid of your calls to input as it's not safe. You should always use raw_input and then convert to a numerical object. How about you try firing up your interpreter and use input() then type in 4 * 5 + 10 ... It's a flaw that is being removed in Python 3.0

sneekula commented: good advice +6
jlm699 320 Veteran Poster

Is there any reason that you're using an array instead of just the built-in list ? Does your code work or is it broken?

jlm699 320 Veteran Poster

The info is stored in the file that is specified in this case it's stored in pickleFile , which points to the file list.dat . Here is scru's code reposted with comments explaining each line:

import cPickle # import module for pickling

# create the list
lst = [1, 3, 4, 5, 6, 7, 8]
# now we open a file, ( 'w' for write mode )
# If the file doesn't exist it is created
# If the file DOES exist, it will be wiped
# using 'a' instead of 'w' will preserve contents
# a = append, w = write, r = read (default)
pickleFile = open("list.dat", "w")
# Dump the object lst to the file pointed to by pickleFile
cPickle.dump(lst, pickleFile)
# Close the file.. no more writing
pickleFile.close()

# Now open the file again... this time for reading
pickleFile = open("list.dat", "r")
# load the contents of pickleFile into the variable lst
lst = cPickle.load(pickleFile)
# Close the file.. no more reading
pickleFile.close()

# Print the results
print lst

Hopefully that helps. If you have any other questions let us know!

jlm699 320 Veteran Poster

Yes, it wrote my input to file. The code works. Maybe you have a typo in your code somewhere. But if you copy-pasted it to this forum then you have something seriously wrong with your python distro.

What version are you using?

jlm699 320 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?

jlm699 320 Veteran Poster

This is the first result from googling 'delete registry key python'

jlm699 320 Veteran Poster

I don't know how you could possibly be getting a tuple object... I used your code exactly and it worked just fine. A tuple is this:

a = (1, 2, 3, 4) # tuple with 4 elements
b = ('a', 'b')   # tuple with 2 elements

# tuples can be iterated over like lists
for item in a:
    print a

Don't know how you could possibly be getting a tuple in there.. Is that all your code?

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

That's an interesting challenge... If it were me I would use a two-tiered scoring system, whereby you could assign a value to the hand itself, ie:

high card = 1
pair = 2
two pair = 3
three of kind = 4
etc...

Then, in the event of a tie, you'd need to compare the actual value of the hand. Do you get my meaning?

Is that what you were asking or am I misinterpreting your question?

jlm699 320 Veteran Poster

I don't know about a "go interactive" command, but if you use pdb (python debugger) and set the pdb mark somewhere, it dumps you out into the interpreter with all your current workspace that the program has worked on so far. It's pretty simple to do, simply import pdb at the beginning of your program and then you mark the "go interactive" portion with the command pdb.set_trace() .

Take note, the pdb interface is kinda strange at first, but this documentation should help to qualm any trepidations you may encounter.

jlm699 320 Veteran Poster

In the future, please use code tags when posting code in this forum, it makes your code actually readable instead of a wall of unformatted, garbled text.

Use code tags like this:
[code=python] # Code inside here

[/code]

jlm699 320 Veteran Poster

plz some code tags about the code:

[code=python] # Put code inside here

[/code]

This will make your code readable on this forum. Also, as per forum guidelines, if you're asking a new question start a new thread, don't go digging up old threads with a similar topic.

jlm699 320 Veteran Poster

Hmm, after taking another look at your method, you must be getting the instance and not just the contents since you're able to call the attrib method... Have you tried using remove(item) instead of remove(f) ?

jlm699 320 Veteran Poster

According to documentation:

Unlike the findXYZ methods this method compares elements based on the instance identity, not on tag value or contents.

Which means that likely your iterator is returning the contents and not the instance itself.

jlm699 320 Veteran Poster

You need to use code tags when posting code in this forum, like so:
[code=python] # Your code in here

[/code]
That will preserve your indents so that your code is readable, and will entice other forum members to actually read your post.

Here's a way to split up a list using slicing:

>>> a = [1,2,3,4,5,6,7,8,9]
>>> b = [ a[:3], a[3:6], a[6:] ]
>>> b
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>>

Is this what you're asking about? It helps us to be more specific in your questions and also to follow all forum guidelines so that we can better answer your questions.

jlm699 320 Veteran Poster

Please use code tags when posting code in this forum like so:
[code=python] # Code goes inside these tags

[/code]

As far as your "plot D2" code, that should be giving you a syntax error, since => is not valid in Python. What exactly is that line supposed to do? As I read it: B = A => threshold means you want to evaluate A >= threshold (if the value of A is greater than or equal to the value of threshold ) and then store it in B , which would naturally return either True or False.

jlm699 320 Veteran Poster

The communicate method "reads all of the output and waits for child process to exit before returning" [ Source ], so in order to work with a program that expects multiple inputs you'll need to communicate with the stdin of the process as such:

proc = Popen('./Ex.sh', shell=True, stdin=PIPE, stdout=PIPE)
proc.stdout.readline()
proc.stdin.write('password\n')
proc.stdout.readline()
proc.stdin.write('123\n')
proc.stdout.readline()
...etc

I think it'd be more efficient to let Python poll the user for input and then pass those as parameters to a shell script.

jlm699 320 Veteran Poster

Okay, so post your code and tell us what the errors that you're getting are. What are you stuck on?

jlm699 320 Veteran Poster

Use code tags when posting code in this forum, or else nobody will be willing to help you:
[code=python] # Code goes in here

[/code]

When using the __str__ method you have to make sure that you are returning a string. Here's an example of proper usage:

>>> class foo(object):
...     def __init__( self, name ):
...         self.name = name
...     def __str__( self ):
...         return self.name
...     
>>> mc = foo('bar')
>>> mc
<__main__.foo object at 0x01D24C30>
>>> print mc
bar
>>>

It sounds like you are returning something other than a string, but it's too hard to read your code without the usage of code tags. I suggest reading the forum guidelines and all posted announcements and then reposting your code and related dilemma.

EDIT: I see it now: Circle = ["Circle"] does not create a string. ["Circle"] is a list with a single element.

jlm699 320 Veteran Poster

Maybe it would be easiest to uninstall and re-install Python. Perhaps you should look at adopting a new IDE as well (I'm sorry I just can't stand IDLE!)

jlm699 320 Veteran Poster

I suggest learning the basics of Python before trying to use it as a web platform. I highly recommend dive into python, which is a free book online that is geared for programmers that already know the basics of writing code in general (control flow, data structures, etc.)

Python wasn't necessarily tailored to creating webpages, but rather to have the ability to do ANYTHING. It's a scripting language at it's core, and the syntax is designed to read like pseudo code. This makes it extremely easy for a programmer coming in from a new language (or even a complete newbie) to look at example code and instantly understand it.

That's not to say that the language is simplistic, as there are plenty of ways to obfuscate code and make it highly unreadable by combining steps, but the natural and most straight forward way is almost always instantly human-readable.

There's plenty of resources on this site as well. I suggest the sticky thread in this forum that's tailored towards beginners. It has plenty of challenges that will help you get into Python quickly. Also, don't be afraid to ask questions, as there are plenty of Python gurus on this site that are willing to help. Just remember to follow the rules and to use code tags when posting code.

I look forward to seeing you around more often, and (hopefully) being able to answer your questions.

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

Alright, here's some psuedo code for how I did it. I had two functions. First I made one to handle each row:

def handle_row(row_a, row_b):
    new_row = []
    Get the length of each row
    compute the difference in length
    if diff > 0:
        extend row_b by diff
    else:
        extend row_a by the absolute value of diff
    for each_item in row_a:
        append the bigger of the two values (row_a[idx], row_b[idx])
    return new_row

The main function acts in almost exactly the same way, except you use handle_row isntead of the max evaluation

EDIT: Now I see that you're not evaluating based on value... simply replacing values that exist... either way, the psuedo code should help you get started. When you run into hiccups post your relevant code and error traceback and we'll help you soldier on

jlm699 320 Veteran Poster

I don't believe that there is... startfile simply launches the program as if it had been executed from the command prompt/shell... It doesn't return anything as far as I can tell, so my answer would be no.

But perhaps there is a way.

jlm699 320 Veteran Poster

This isn't necessarily appropriate for the Python forum but:

len_x = size(x)
for i = 1:len_x
    x(i)
end

Now forgive me, I haven't used Matlab in years; however if you need more help you'll find the MATLAB docs here.

jlm699 320 Veteran Poster

To use code tags:

[code=python] # This is my PYTHON code # It goes between the code(=syntax) brackets

[/code]

If you use code tags your question will be easier to read, thus easier to answer by our forum members

jlm699 320 Veteran Poster

Would i just do something like

if choice ==1 :
do this

if choice ==2:
do this

ect?

Yeah pretty much. That's the most straight forward way to approach this problem

usr_inp = raw_input( 'Enter your choice (1-3): ' )

if usr_inp == '1':
    # do something for 1
elif usr_inp == '2':
    # do another thing for 2
elif usr_inp == '3':
    # do the number 3 thing
else:
    print 'Invalid Option'
jlm699 320 Veteran Poster

Please follow the forum guidelines when posting, most importantly when you post code. If you don't use code tags the code turns out as it did above and nobody wants to look at the crazy wall of unformatted text.

Use code tags like this when posting code in this forum:
[code=python] # Put your code inside here

[/code]]/noparse]

It also helps if you give us the portion of code that causes your issue and a concise example of how to reproduce the issue... (ie provided input, expected output, actual output)[noparse]

# Put your code inside here

]/noparse]

It also helps if you give us the portion of code that causes your issue and a concise example of how to reproduce the issue... (ie provided input, expected output, actual output)