jlm699 320 Veteran Poster

Use the button_object.config(text=my_text) option. Source

jlm699 320 Veteran Poster

sorry.I saw links but i can not solve my problem yet.
...
.but how can i do it?

You should really follow those links that woooee provided. For this type of task you should be either using pexpect or subprocess PIPES, not os.system .

jlm699 320 Veteran Poster

How about this:

>>> a = [[1,2,3], [4,5,6], [7,8,9]]
>>> new_a = []
>>> for each_a in a:
...     new_a += each_a
...     
>>> new_a
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>
jlm699 320 Veteran Poster

Maybe it's four 8-bit numbers together?

>>> i = '100010101001000010000011111001010'
>>> first_num = int(i[:8],2)
>>> secnd_num = int(i[8:16],2)
>>> third_num = int(i[16:24],2)
>>> fourt_num = int(i[24:32],2)
>>> first_num
138
>>> secnd_num
144
>>> third_num
131
>>> fourt_num
229
>>>
jlm699 320 Veteran Poster

Are you describing a "race condition"? If you are working with something like this you are not a newbie, this is complex stuff.

try googling "data race condition" and learn about the different methods to solve this fundamental software design issue.

jlm699 320 Veteran Poster

The backslash (\) is used for an "escape character". So \t is the escape character for a tab, \n is for newline, and \" or \' are escapes for a double and single quote respectively.

Let's say we have a string: 'Hi my name is Charlie' . The single quotes are what tells the interpreter that every character in between is part of the string. Now if we wanted to use a contraction inside that string and change it to: 'Hi my name's Charlie' , you can see that the string (ie, what's inside the quotes) is actually only 'Hi my name' and the rest is attempted to be interpreted to Python code.

To solve this there are two methods:

1) Change the type of quotation marks that are used on the string, so we would instead have: "Hi my name's Charlie" 2) Escape the "inner" quotation so that it is interpreted as the character instead of the syntax marker: 'Hi my name\'s Charlie' HTH

jlm699 320 Veteran Poster

y will always be equal to y. I think you meant if y == 'y' . Like wise for the not equals (note you can also use != ). You really don't need to have another clause there, because if y is not equal to the character 'y' you already know it's not equal so you don't need to specifically check again. You can simply use if y == 'y' and else .

Finally, you made a class. That's not the way you're supposed to use a class, you should have defined a function.

jlm699 320 Veteran Poster

You could do a simple while loop:

import subprocess

repeat = 'y'
while repeat == 'y':
    subprocess.call(["programname"])
    repeat = raw_input("Would you like to run again? (y/n) ")
jlm699 320 Veteran Poster

Your code is awaiting your next raw_input at the "C" prompt.... You should be comparing the value of sel . Also, you've done the exact same thing as before. You can't print the value before you get it from the user or your code will complain about that object not existing. You need to modify your code like so:

sel = raw_input("select C for c to f, or F for f to c ? ")
if sel == 'C':
    c = raw_input("what temperature (celius) do you need converted? ")
    print "%s degrees celsius is equal to %s degrees Farenheit" % (c, 32+(212-32) / 100.0 * c)
elif sel == 'F':
    f = raw_input("what temp (farenheit) do you need converted? ")
    print "%s degrees farenheit is equal to %s degrees celcius" % (f,(f-32) * 100.0 / (212-32))
jlm699 320 Veteran Poster

That's because you're trying to print the result before you even ask the user for the number that they want to input.

jlm699 320 Veteran Poster

It looks like you're using a Python version that is not 3.X ... so in that case you should be using raw_input() instead of input().

raw_input stores the user's input as a string, which is the way input() works in Python 3.0 and up

jlm699 320 Veteran Poster

This would also likely require that your Python program run in the background as a service. It would need to monitor the presence of a USB flash drive and act accordingly when it detected one. There is information in this forum for setting up a service in Windows if you search for it.

jlm699 320 Veteran Poster

At anytime, dinner... literally anytime.

jlm699 320 Veteran Poster

This time it's because '?' is a special character in regular expressions (you're using it inside your group). The question mark indicates a greedy match of 1 or more (where as the asterick (*) is a greedy match of 0 or more). To match the question mark character itself you need to escape it in your regex like so: \? . The full regular expression then becomes:

>>> c = re.compile('<a href="/List\?ratings=7">(.*?)</a>')
>>> c.findall(t)
['7.2']
jlm699 320 Veteran Poster

So you literally take your object and perform a str(object) ? And that's what you're trying to turn back into a proper python object? For that you would use a simple eval():

to = ['This is my list', 'With Stuff', [0,1,2,3,4], 'Foo', 112, 5, '57 + 1']
my_saved_ver = str(to)
tr = eval(my_saved_ver)
print type(tr)             # Prints <type 'list'>
print type(my_saved_ver)  # Prints <type 'str'>

HTH

jlm699 320 Veteran Poster

Use code tags, Makes it easier for us to read.

Let me explain the code:

[B]import[/B] sys
[B]print [/B]>> sys.stderr, 'Fatal error: invalid input!'

logfile = open('/tmp/mylog.txt', 'a')
[B]print[/B] >> logfile, 'Fatal error: invalid input!'
logfile.close()
  1. We import the sys module documentation here
  2. We print the message 'Fatal error... etc' to the system's standard error pipe

  3. Open a file located at /tmp/mylog.txt in 'append' mode, which means open it for writing but leave the existing contents intact (alternately could say 'w' for 'write' mode, which clears the contents when it opens the file)

  4. Print the message into the logfile
  5. Close the logfile.
jlm699 320 Veteran Poster

hey, I tried it with
mpaaget = re.compile('<div class="info-content">(.*?)</div>')
but then I got something else . Could it be because there is a new line after <div class="info-content"> ? How do I take care of that?

Yes, the white space does not fit into your regular expression. Modify like so to match 0 or any number (*) of white space characters (\s):

>>> m = re.compile('<h5><a href="/mpaa">MPAA</a>:</h5>\s*<div class="info-content">\s*(.*?)\s*</div>')
>>> m.findall(h)
['Rated PG for some scary moments and mild language. (also 2009 extended version)']
>>> m.match(h)
>>>
jlm699 320 Veteran Poster

Personally I'd use regular expressions like so:

>>> import re
>>> regex_compiled = re.compile('^<Ranking: (.*) \((.*)\)>$')
>>> input_data = """<Ranking: AA (John)>
... <Ranking: CA (Peter)>
... <Ranking: TA-A (Samantha)>
... """
>>> for each_entry in input_data.split('\n'):
...     regex_match = regex_compiled.match(each_entry)
...     if regex_match:
...         print 'Ranking: % 5s  Name: %s' % (regex_match.group(1), regex_match.group(2))
...     
Ranking:    AA  Name: John
Ranking:    CA  Name: Peter
Ranking:  TA-A  Name: Samantha
>>>

If you need any specific part of that explained I'd be happy to do so.

If you're really in need of using string methods I'd do something like the following:

>>> for each_entry in input_data.split('\n'):
...     rank_search = '<Ranking: '
...     idx = each_entry.find(rank_search)
...     if idx != -1: # string.find returns -1 when not found
...         idx += len(rank_search) # Increase idx to where rank_search ends
...         end_idx = each_entry.find(' (', idx) # idx as starting point for find
...         print 'Ranking: % 5s  Name: %s' % (each_entry[idx:end_idx], each_entry[end_idx+2:-2])
...     
Ranking:    AA  Name: John
Ranking:    CA  Name: Peter
Ranking:  TA-A  Name: Samantha
>>>
jlm699 320 Veteran Poster

Okay so returning signals the end of a function as well as confirms the functions ability to pass a variable made in the function?

Yes, a return statement exits the function and passes a value back to the point in code that called it. You can return any object no matter how complex. By omitting a value and just using return you are returning a None type object (ie, nothing).

jlm699 320 Veteran Poster

My second question is:\

def costTotal(self, cost=100):

what exactly is this cost=100?

In a function declaration, the items inside the parenthesis are called parameters. These are basically variables that are "passed" to the function. By assigning a value (of 100) to a parameter you are making it optional. By optional, I mean that you aren't required to pass that value to the function in order for it to work. When making it optional you provide a default value. So you can call the function two ways:

self.costTotal()

Inside the function, if you were to add a print cost as the first line you'd see that cost is equal to 100 (the default value). Now if you called the function like this:

self.costTotal(250)

Your print statement would show that cost is now equal to 250.

Hope that clears it up.

jlm699 320 Veteran Poster
class Cat(object):
    def __init__(self, num=1, age=1):
        self.num = num
        self.age = age
    def costTotal(self, cost=100):
        self.cost = cost
        self.costTotal = self.cost + self.cost * self.num + self.cost * self.age
    def printIt(self):
        print self.num, self.age
        print self.costTotal

cat = Cat(2,3)
cat.printIt()

[1] I cannot get the second printIt worked. It showed <bound method .....
I got self.num, self.age working but not the second line. What did I do wrong?

You need to call the function costTotal and provide the parameters if needed. So your line that says print self.costTotal should actually be print costTotal() ... then in your costTotal function I believe the last line should be return self.cost + self.cost * self.num + self.cost * self.age . The way it is now, you're effectively "erasing" the function costTotal and replacing it with the value of that calculation.

I don't understand your second question.

jlm699 320 Veteran Poster

Yes, you could create a general Student class and then go about creating instances of the class. Each instance would represent a different student and would contain the necessary data to individualize and represent the student's details.

If you look around this forum you'll find examples of "shapes" and "pets" classes that others have provided. They are very basic examples of making a class and then creating instances of said class. That should get you well on your way

jlm699 320 Veteran Poster

Here's a regular expression that should work for you: re.split('([.!?] *)', a) If you need it broken down and explained for you I can do that; otherwise, it may be more fun to investigate using the documentation and pick it apart to learn how it works!

Here's me using your test string:

>>> import re
>>> a = "this is the test string! will it work? let's find out. it should work! or should it? oh yes. indeed."
>>> rtn = re.split('([.!?] *)', a)
>>> ''.join([each.capitalize() for each in rtn])
"This is the test string! Will it work? Let's find out. It should work! Or should it? Oh yes. Indeed."
>>>

At the end there I did a list comprehension. To break it out it would be:

>>> str_pieces = []
>>> for each in rtn:
...     str_pieces.append(each.capitalize())
...     
>>> ''.join(str_pieces)
"This is the test string! Will it work? Let's find out. It should work! Or should it? Oh yes. Indeed."
>>>
jlm699 320 Veteran Poster

Wow, that code is pretty long!

Here's a shortened version:

import string

# Strings are already iterable so we don't need to convert to list
message = raw_input('Enter a string: ')
# Make a string of a space plus all the lower case letters (the first
## 26 indices of the string.letters object is all lowercase).
my_letters = ' ' + string.letters[:26]

message_number = []

# Just iterate over the message, we don't care about index
for each_char in message:
    message_number.append(my_letters.index(each_char.lower()))

print message_number
raw_input('\nPress any key to exit...')

If there's anything you don't understand please don't hesitate to ask.

jlm699 320 Veteran Poster

i am having diff in understanding this code..i am supp to do it in python

for qid,query in "as2.qrys": 
       for word in query: 
         docs = set(index[word]) 
         for doc in docs: 
           number_of_matched_words [doc] ++ 
       for doc in matches: 
         if number_of_matched_words[doc] == length(query): 
           print qid, 0, doc, 0, 1, 0

Is this psuedo-code that you're supposed to translate into Python?

jlm699 320 Veteran Poster

28 Minutes Ago | Add Reputation Comment | Flag Bad Post

Hah, that's awesome...

One last problem with my script, it returns this error message...

Traceback (most recent call last):  File "C:/Python26/Renamer 3", line 23, in <module>    os.rename(fname, b)WindowsError: [Error 2] The system cannot find the file specified.Traceback (most recent call last):
  File "C:/Python26/Renamer 3", line 23, in <module>
    os.rename(fname, b)
WindowsError: [Error 2] The system cannot find the file specified.

This indicates that the "from" file is not located at C:/Python26/Renamer 3... Is that correct? C:/Python26 is likely the current working directory (it's where python.exe is located). And since you just gave the filename as Renamer 3, it assumed this file was in that directory.

To avoid this you can use an absolute path (ie, C:/Foo/Bar/Choo/Renamer 3 or wherever the file is located)

jlm699 320 Veteran Poster

So you want to use the value of Templng for the default value of the to parameter in the translate function?

jlm699 320 Veteran Poster

It's hard to tell whether you did this or not since you didn't give us all your code, but I'm assuming that before assigning to Templng you used global Templng to let the local scope know you meant to use the global variable and not just create a new local one?

Or maybe that's the whole problem.

jlm699 320 Veteran Poster

How do I call the program from the command line?

Type your python command (*if you haven't set it up you'll need to use the full pathname to python.exe or pythonw.exe), then the name of your script, then the command line arguments... here's an example:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>
C:\>edit cmd_args.py

C:\>C:\Python26\python.exe cmd_args.py these are command line args


C:\>

Note: The cmd_args.py simply contained the following:

import sys
print sys.argv

In my environment I've set the "python" command to point to "C:\Python26\python.exe", that way when I'm in the cmd line I can just type "python <script_name> [args]"... it's much faster.

jlm699 320 Veteran Poster

You have a number of issues in your code revolving around scope.

Here are the first few that jumped out at me:

1) In your dig_sum function, you refer to i but never define it (in your while loop). Perhaps you're referring to the i from the avo function or from the global scope. If that is the case you should be passing it to the function specifically, not relying on the global value. Otherwise you need to define a starting point and somehow increment it inside the while loop.

2) Same as above but in the avo function you're referencing and modifying the list named arr. Again, if you really want to modify this list you should be passing it and not using globals.

Note: number 1 is the reason that your program hangs. You don't modify the value of i so that while loops simply runs forever.

EDIT: Here's a cleaner way of doing a digital sum using list comprehension:

>>> def dig_sum(n):
...     ''' Prints the digital sum of number n. '''
...     return sum([int(each_numeral) for each_numeral in str(n)])
...     
>>> dig_sum(52)
7
>>>

And to break that out:

>>> def dig_sum(n):
...     ''' Prints the digital sum of number n. '''
...     dsum = 0
...     for each_numeral in str(n):
...         dsum += int(each_numeral)
...     return dsum
...     
>>>
jlm699 320 Veteran Poster

When you return an object it isn't just automagically added to the current namespace... you need to actually store it in something.

All you'll need to do is say graph = plot_it(...) , savvy?

jlm699 320 Veteran Poster

wow thanks for that dude I was actually wondering how to create private variables in Python. That really helped :)

Yes, but be forewarned it's psuedo-private. You can still see and access the variable, it's just obfuscated with the Class name. Look:

>>> class Cpriv(object):
...     def __init__(self):
...         self.__privy = 'I am hidden'
...     
>>> C = Cpriv()
>>> dir(C)
['_Cpriv__privy', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
>>> print C._Cpriv__privy
I am hidden
>>>
jlm699 320 Veteran Poster

suppose i have 10 different functions.

i generate a random no. between 1 to 10.
depending on its value i want to call the fucntion.
eg. no. 3 call func, no. 8 calls func 8... etc.
how do i do it using a loop without using the if else statement as it makes the code too long.

A dictionary. The key is the number, the value is the function.

Generate random number, then do something like my_function_dict[my_random_number]() . Get it?

EDIT: To illustrate:

>>> def funcA():
...     print 'A'
...     
>>> def funcB():
...     print 'B'
...     
>>> def funcC():
...     print 'C'
...     
>>> func_dict = {1:funcA, 2:funcB, 3:funcC}
>>> random_number = 2
>>> func_dict[random_number]()
B
>>>
jlm699 320 Veteran Poster
for i in range(len(dict)):
        dict[i] = dict[i][0:len(dict[i])-2]

What is that? What are you doing?

EDIT: Also remember that dict is a reserved word in Python I suggest that you change the name

jlm699 320 Veteran Poster

The functions work but it prints "unrecognised input" even though one of the if statements has been completed.

What functions?

The first code is not working because you're not iterating over your input anymore.

The second code is not working because your indentation is royally screwed up. Everything should be within the for loop.

jlm699 320 Veteran Poster

Sorry, i need the try except statements.

Unless your teacher is specifically telling you to use them in this manner, you really don't. And if he/she is, then I feel bad for you because your teacher is a terrible programmer.

If you're required to use them, then at the very least you should be printing any exception values like so:

try:
    # Massive try block here
except:
    print sys.exc_value
    sys.exit()

That way at least you'll have a small clue as to why your program is failing, but really you should print out the entire traceback.

I don't really understand what you mean. Could you link me to more information or explain in more detail? Thanks.

It would be something like this:

my_number = ''
for each_char in usr_input:
    if each_char in numbers:
        my_number += each_char
    else:
       stack.append(int(my_number))
       my_number = ''

Does that clear it up? Or was there something else that you didn't understand?

jlm699 320 Veteran Poster

My first suggestion is to remove the giant try/except block. If you make a syntax error your program will quit and never tell you the reason why. That is extremely poor Python coding and opens the door for you to create debilitating issues in your code.

Now, in order to support numbers > 9 you'll need to basically append each numeral onto a string before doing your int() conversion.

An easy way to do this would be to have a string container... we'll call it my_numbers . In your if mystr in numbers statement, you'll be doing string concatenation (ie, my_numbers += mystr ) instead of int conversion. Then, in each of your "operator" cases, you'll take the previous my_numbers object, convert it to an int, add it to your stack, and then clear the object with my_numbers = '' .

That's only one possible way to do it... Your most efficient method would be using regular expressions, but that's probably way beyond the scope of your lesson.

jlm699 320 Veteran Poster

I'd look into beautifulsoup if you're looking to break this thing down into an object hierarchy type structure. I haven't used it much, but I know there's plenty of examples on this site of how to implement it.

jlm699 320 Veteran Poster

If you search the forum you'll see this question has been asked a bajillion times.

Here's an example from earlier today.

jlm699 320 Veteran Poster
if player[0] != "r" or player[0] != "p" or player[0] != "s":
        print "incorrect choice entered"

Just a minor logic error. This should be:

if player[0] != "r" and player[0] != "p" and player[0] != "s":
        print "incorrect choice entered"
jlm699 320 Veteran Poster

Not exactly, I'd like to take the values that are being sorted on and put them into a new list/dict etc.

For example, extracting only these values from the dictionary above:
new_list = ('2.5','3.5','3.9','4.0','3.1')

Okay... how about this:

>>> data_dict = {
... '1234': ['Matt', '2.5', 'CS'], 
... '1000': ['John', '4.0', 'Music'], 
... '1023': ['Aaron', '3.1', 'PreMed'], 
... '1001': ['Paul', '3.9', 'Music'], 
... '9000': ['Kris', '3.5', 'Business']
... }
>>> [data[1] for data in data_dict.values()]
['2.5', '3.5', '3.9', '3.1', '4.0']
>>>

That's just a quick list comprehension that will extract the second element (at index 1) from each list (which is stored as the "value" part of each dictionary entry.

jlm699 320 Veteran Poster

Wow, thanks a lot! The idea of using a method didn't cross my mind. But for one of my test cases I changed the numbers to two-digit numbers and now the first two-digit number in a list becomes "ripped" as in {a:}. I am just wondering how does this happen? How come it messes up only the first number?

Because a string is an iterable object. When using the list() method, it converts any such object to a list by iterating over it. Example:

>>> list( (1,2,3,4,5) )
[1, 2, 3, 4, 5]
>>> list( 'Hi my name is bob' )
['H', 'i', ' ', 'm', 'y', ' ', 'n', 'a', 'm', 'e', ' ', 'i', 's', ' ', 'b', 'o', 'b']
>>> [ 'Hi my name is bob' ]
['Hi my name is bob']
>>>

Just use the square brackets instead of list() and you should be good to go.

jlm699 320 Veteran Poster

Ah ha! That worked! Now, since you're putting it in a list to sort the values, is there also a way to separate those values you are sorting on into a list by themselves?

Is this what you mean?

>>> my_dict = {'a':1, 'b':2, 'c':3}
>>> my_dict.keys()
['a', 'c', 'b']
>>> my_dict.values()
[1, 3, 2]
>>>
jlm699 320 Veteran Poster

Can you help?

Why, yes! This case would be a good one to use the dictionary's get method, which will allow you to determine if the key is already in the dictionary or not, and act accordingly.

def file_to_dict(fname):
    f = open("file.txt")
    d = {}
    for line in f:
        columns = line.split(" ")
        letters = columns[0]
        numbers = columns[1].strip()
        if d.get(letters):
            d[letters].append(numbers)
        else:
            d[letters] = list(numbers)
    print d
    
if __name__ == "__main__":
    fname = "file.txt"

Try that on for size.

Basically, by default get will return None if the key is not in the dictionary (you can pass a second parameter to mean default but I prefer None type). So first we check to see if the key is in the dictionary already. If it is, we use the list method append to add the new number onto the end of our list. If the get statement returned None, we instead do what you used to do (create a list as the value to the key).

HTH

jlm699 320 Veteran Poster

Anyone know how to take the readlines() blob and split it up into an array?

The function readlines() already gives you an "array" (it's list in Python). So I guess that part's solved

Welcome to the forum Linky. Please, in the future use code tags (or any other appropriate tag) when you're posting in the forums. It helps us all read your posts better and therefore we're able to give you more solid help and quicker!

This will give you pretty output like this (this is your code reposted w/ tags):

def parseline(input,start,stop):
    for line in input.readlines(): 
        if ":" in line:
            line = line[start:stop]
            print line

--
Now on to your problem: if you're looking to store those numbers instead of merely print them you can just start with an empty list at the beginning of your function, and then append each value to it, which you can then pass back to the calling code:

def parseline(input,start,stop):
    my_numbers = []
    for line in input.readlines(): 
        if ":" in line:
            line = line[start:stop]
            my_numbers.append(float(line))
    return my_numbers

Then in your code when you call parseline(x,y,z) simply use something like numbers = parseline(x,y,z) instead. Then all you need to do is use numbers.sort()

EDIT: Also note that in your function I converted the number to a floating point with float()

EDIT 2: It's pretty common practice in Python to use 4 spaces instead of a tab. Most editors can be set to use a 4 space tabstop …

jlm699 320 Veteran Poster

Could someone explain how this works?

If I'm not mistaken \b means "backspace". So in this example you're writing a seven digit numeral to the screen with %07d and then seven "backspaces" to clear those numerals before writing the next number.

jlm699 320 Veteran Poster

Here's an indexing example:

>>> mydata = [0.0] * 5
>>> mydata
[0.0, 0.0, 0.0, 0.0, 0.0]
>>> mydata[2] = 45
>>> mydata
[0.0, 0.0, 45, 0.0, 0.0]
>>> mydata[0] = 1.0
>>> mydata
[1.0, 0.0, 45, 0.0, 0.0]
>>> mydata[2]
45
>>>
jlm699 320 Veteran Poster

Actually, the first parameter in the brackets is the index i want to store the value at.

ST=[0.0]
    ST.insert(2,2.2)
    ST.insert(0,0.0)
    ST.insert(3,3.3)
    ST.insert(4,4.4)
    ST.insert(1,1.1)
    ST.insert(5,5.5)
    print ("test point")
    print("my test val 1= ",ST.pop(1))
    print("my test val 2= ",ST.pop(2))
    print("my test val 3= ",ST.pop(3))
    print("my test val 4= ",ST.pop(4))
    print("my test val 5= ",ST.pop(5))

so this should print
my test val 0= 0.0
my test val 1= 1.1
my test val 2= 2.2
my test val 3= 3.3
my test val 4= 4.4
my test val 5= 5.5

Yes, but when you're inserting to an index, that index must exist. Index 2 does not exist in a single element list (only index 0 and index 1). When you insert, you're also extending your list by one. What you want is to declare a list with 0.0 of the desired length as I demonstrated earlier and instead of insert you should be using indexing.

EDIT: Also note that using pop removes that element from the list. Once again, you should be using indexing.

jlm699 320 Veteran Poster

mydata.append((45, 2)) maybe working (doesn't give bugs) but i don't know to check if its gone to where it should since i don't have an extraction method

Why don't you just fire up your interpreter and see what's happening:

>>> mydata = [0.0]
>>> mydata
[0.0]
>>> # mydata only has one element
>>> mydata = [0.0] * 5
>>> mydata
[0.0, 0.0, 0.0, 0.0, 0.0]
>>> # Now mydata has 5 elements
>>> mydata.append((45,2))
>>> mydata
[0.0, 0.0, 0.0, 0.0, 0.0, (45, 2)]
>>> # Using append places the object on the end of the list (this object is a tuple
>>> mydata.insert(2, 45)
>>> mydata
[0.0, 0.0, 45, 0.0, 0.0, 0.0, (45, 2)]
>>> # Using insert (notice index first) "inserts" the object (45) to position 2; however it pushes the rest of the elements up a notch
>>> mydata[4] = 24.2
>>> mydata
[0.0, 0.0, 45, 0.0, 24.199999999999999, 0.0, (45, 2)]
>>> # Looks like indexing is what you should be using.  This changes the element at index 4
>>>

I hope that was clear enough. If not let me know

jlm699 320 Veteran Poster

Is it possible to keep writing the output of a program on the same line instead of moving to a new line every time? The output should be written over the preceding output. An example would be a kind of counter...
say a number that counts from 1 to 10 ...
The normal output of a while loop would be
1
2
3
4
5
etc..

What I want is something that will display 1.. erase it and then display 2.. erase that and display 3 and so on..

To overwrite the previous output you could use the system command os.system('cls') on Windows or os.system('clear') on Linux.

But if you're looking for single character control you'll need to look into curses, which isn't readily available for Windows.

To print on the same line you can end your print statement with a ',' so that instead of printing a new line it prints a space... But that won't help you to clear the previous value