Re: [Tutor] Variables and constants [was Re: working with strings inpython3]

2011-04-19 Thread bodsda
And presumably cleans up the leftover object with the value of 42 when it 
changes to point at the 43 object? 

Or does it leave all changes in memory until the program exits?

Bodsda.
Sorry for top posting, my phone won't let me change it 
Sent from my BlackBerry® wireless device

-Original Message-
From: Steven D'Aprano 
Sender: tutor-bounces+bodsda=ubuntu@python.org
Date: Wed, 20 Apr 2011 04:24:03 
To: tutor
Subject: [Tutor] Variables and constants [was Re: working with strings in
 python3]

Rance Hall wrote:

> Variables are variable, that's why we call them variable.
> Constants are constant, and that's why we call them constant.

And Python has neither variables nor constants in the sense that (say) 
Pascal, C or Fortran have, even though we often use the same words.

The differences are quite deep, but they're also subtle.

In classic programming languages with variables and/or constants, the 
model is that names like "x" refer to *memory locations*. If the name is 
a variable, the compiler will allow you to mutate the value stored at 
that memory location; if the name is a constant, it won't. But once a 
name "x" is associated with memory location (say) 123456, it can never 
move. But note that the "variability" or "constantness" is associated 
with the *name* (the memory location), not the value.

In languages like Python, names are associated with values, without 
reference to memory locations. In this case, the "variability" or 
"constantness" is associated with the *value*, not the name.

Consider x = 42; x = x+1. In Pascal, C or Fortran, this will actually 
change a block of memory that had the value 42 into 43 instead:

The name x points to a memory location with value 42.
Leave the name pointing to the same place, but change the value to 43 
instead.

In Python, the situation is different:

The name x points to an object with value 42.
Leave the object 42 alone, but change the name x to point to an object 
with value 43 instead.



-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Gtk - relational data display and edit

2011-04-26 Thread bodsda
Hi,

I am reading in data from a csv file which will be in a format like this

User1, attrib1, attrib2
User2, attrib1, attrib2
Etc.

And need to display this in a window. My initial thought was to use gtk.Entry 
widgets because I will need to edit this data, but I don't think this will work 
as I will also need to read the data back, in relation to the user column, e.g 
I will have something like

[Psuedocode]
For I in entries:
A = usercolumn
B = attrib1column
C = attrib2column

Somefunction(A,B,C)
[/psuedocode]

I don't think I could use this method with entry boxes as I have no idea how 
many entries there will be (column length will be fixed) so I can't create the 
entry widgets beforehand

Anyone have any suggestions?

Thanks,
Bodsda
Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Gtk - relational data display and edit

2011-04-26 Thread bodsda
Thanks for your reply.

Unfortunately I can't change the data format because it is output from a closed 
source app.

I can't figure out a way to create the entry widgets on the fly because they 
need to be bound to a variable to attach them to a gtk.Table and to be able to 
read the data from them

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: Walter Prins 
Date: Tue, 26 Apr 2011 16:55:36 
To: 
Cc: 
Subject: Re: [Tutor] Gtk - relational data display and edit

On 26 April 2011 16:34,  wrote:

> Hi,
>
> I am reading in data from a csv file which will be in a format like this
>
> User1, attrib1, attrib2
> User2, attrib1, attrib2
> Etc.
>

Why would the data be in this format?  Are you defining it?  Reason I ask is
that, relationally speaking, (e.g. database design-wise) this is a
denormalised representation and you'd do better to store a single attribute
per record.  E.g. have entities, User, Attrib, and have relationship table
User_Attrib that contains only user, attrib pairs.  But, maybe such ideas
are overkill for your app.



> And need to display this in a window. My initial thought was to use
> gtk.Entry widgets because I will need to edit this data, but I don't think
> this will work as I will also need to read the data back, in relation to the
> user column, e.g I will have something like
>
> [Psuedocode]
> For I in entries:
>A = usercolumn
>B = attrib1column
>C = attrib2column
>
>Somefunction(A,B,C)
> [/psuedocode]
>
> I don't think I could use this method with entry boxes as I have no idea
> how many entries there will be (column length will be fixed) so I can't
> create the entry widgets beforehand
>
> Anyone have any suggestions?
>

Well if you can count the number of entries on reading the file (whatever
the shape of the file) then in principle you can dynamically create the
correct number of entry boxes on the fly.  Of course, if you store one
attribe per record, then counting the number of attributes (records) for a
given user becomes quite easy of course. But even if you don't do this, and
you have the file structure you described, you can code reader code that
would internally store the attributes and the number of attributes for each
user, enabling you to write code to create the UI with the appropriate
number of entry widgets.

Walter

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python program with multiple answers

2011-05-11 Thread bodsda
Hi,

I would suggest appending the dice[roll] to a new list just after the print 
statement, then in the quit block order the list and then loop over it and 
print each entry.

Hope this helps,
Bodsda
Sent from my BlackBerry® wireless device

-Original Message-
From: Johnson Tran 
Sender: tutor-bounces+bodsda=ubuntu@python.org
Date: Wed, 11 May 2011 03:49:12 
To: 
Subject: [Tutor] Python program with multiple answers

Hi Guys, 

I've been working on a Python program where I create an 8 ball that will allow 
you to ask questions and will reply back with 20 possible answers. It will be 
continuous until the user says quit. My program works fine although I am trying 
to add something more to it, where when the user quits, it will present all the 
answers that the user got again and display them in alphabetical order...if 
anyone could point me in the right direction it'd be really helpful...my 
program so far is : (which works fine with no errros)



import random
dice = ("Without a doubt", "It is certain", "It is decidedly so","Yes", "For 
Sure", "No", "Dont count on it", "Try asking again","Reply hazy, try again", 
"Confucious says 'No'", "Better not tell you now","Cannot predict 
now","Concentrate and ask again","My reply is no","Outlook not so good","Very 
doubtful","Outlook is good","Most likely","As I see it, yes","I do not 
understand the question")
while True:
choice = raw_input("Type 'ask' to ask a question. Type 'quit' to 
quit.\n")
if choice == "ask":
raw_input("Please enter your question:\n")
roll = random.randint(0, 10)
print dice[roll]
raw_input()
elif choice == "quit":
True = 0
raw_input()
else:
print "Error -- Try again\n"





Thanks,

JT

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to sort the file out

2011-09-06 Thread bodsda
I'm also slightly confused. Why does file one start at 1, but file 2 starts at 
3. Why not just duplicate file2?

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: lina 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Wed, 7 Sep 2011 12:46:37 
To: tutor
Subject: [Tutor] how to sort the file out

HI, I have two files, one is reference file, another is waiting for adjust one,

File 1:

1 C1
2 O1
3 C2
4 C3
5 H3
6 C7
7 O2
8 H22
9 C6
10 H61
11 C5
12 H5
13 C4
14 C8
15 C9
16 C10
17 O3
18 C11
19 C12
20 O4
21 C13
22 C14
23 C15
24 C20
25 H20
26 C16
27 H16
28 C17
29 H17
30 C18
31 O6
32 H62
33 C19
34 O5
35 C21

File 2:
3 H16
4 H5
6 H61
7 H17
9 H20
12 H3
13 C1
14 O1
15 C2
16 C3
17 C4
18 C5
19 C6
20 C7
21 C8
22 C9
23 C10
24 O3
25 C11
26 C12
27 O4
28 C13
29 C14
30 C15
31 C20
32 C19
33 C18
34 C17
35 C16
36 O5
37 C21
38 O6
39 H62
40 O2
41 H22

I wish the field 2 from file 2 arranged the same sequence as the field
2 of file 1.

Thanks for any suggestions,

I drove my minds into nuts already, three  hours passed and I still
failed to achieve this.

-- 
Best Regards,

lina
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] If statement optimization

2011-09-16 Thread bodsda
Hi,

In a normal if,elif,elif,...,else statement, are the conditions checked in a 
linear fashion?

I am wondering if I should be making an effort to put the most likely true 
condition at the beginning of the block

Thanks,
Bodsda 
Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] If statement optimization

2011-09-16 Thread bodsda
Thanks for the explanation - very clear.

Cheers,
Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: Steven D'Aprano 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Fri, 16 Sep 2011 20:43:45 
To: Tutor - python List
Subject: Re: [Tutor] If statement optimization

bod...@googlemail.com wrote:
> Hi,
> 
> In a normal if,elif,elif,...,else statement, are the conditions checked in a 
> linear fashion?

Yes.


> I am wondering if I should be making an effort to put the most likely true 
> condition at the beginning of the block

Probably not. The amount of time used in the average if...elif is 
unlikely to be significant itself. Don't waste your time trying to 
optimize something like this:


if n < 0:
...
elif n == 0:
...
else:
...


However, there are exceptions.

If the tests are very expensive, then it might be worthwhile putting the 
most likely case first. Or at least, put the cheapest cases first, leave 
the expensive ones for last:

if sum(mylist[1:]) > 1000 and mylist.count(42) == 3 and min(mylist) < 0:
 ...
elif len(mylist) < 5:
 ...

I probably should swap the order there, get the cheap len() test out of 
the way, and only perform the expensive test if that fails.


If you have LOTS of elif cases, like *dozens*, then firstly you should 
think very hard about re-writing your code, because that's pretty poor 
design... but if you can't change the design, then maybe it is 
worthwhile to rearrange the cases.

If you have something like this:


if s == "spam":
 func_spam(x)
elif s == "ham":
 func_ham(x)
elif s == "cheese":
 func_cheese(x)


you can often turn this into a dispatch table:


table = {"spam": func_spam, "ham": func_ham, "cheese": func_cheese}
func = table[s]  # lookup in the dispatch table
func(x)  # finally call the function


Note that inside table, you don't call the functions.

This pattern is especially useful, as lookup in a table in this manner 
takes close enough to constant time, whether there is one item or a million.



-- 
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] string formatting

2011-09-19 Thread bodsda
Is there any additional overhead of using the locals() or format(locals()) 
instead of a tuple? - the format option is a double function call so I would 
expect that to be considerably slower

Thanks,
Bodsda
-- my phone won't let me bottom post, sorry 
Sent from my BlackBerry® wireless device

-Original Message-
From: Wayne Werner 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Mon, 19 Sep 2011 12:47:01 
To: Pirritano, Matthew
Cc: 
Subject: Re: [Tutor] string formatting

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] paper scissors

2011-09-24 Thread bodsda
The %s signifies that a string will be provided to go there.

The % after the string signifies that the following variable/strings/tuple will 
contain the items to be placed where the %s's are (in order)

The tuple (wins, losses) are the two items that should replace the %s's 

Be aware that there are other place holders such as %i and %d that expect a 
certain data type. With %s, if it is not a string that is given to it, it will 
attempt to be converted to a string first.

Hope this helps,
Bodsda  
Sent from my BlackBerry® wireless device

-Original Message-
From: bob gailer 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Fri, 23 Sep 2011 15:02:44 
To: *tutor python
Subject: Re: [Tutor] paper scissors

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] where to look for python codes

2011-09-29 Thread bodsda
I would suggest looking on http://ubuntuforums.org for the “Beginner 
programming challenges“ - there is an index of past challenges as a sticky in 
the programming talk subforum. A large number of entries for these challenges 
are in python, and as the name implies, the submissions are usually written by 
beginners.

The code will not be enterprise standard, but it should be a good insight into 
how others write python programs

Hope this helps,
Bodsda,
Ubuntu beginners team

P.S: sorry for the top post, smartphone limitation 
Sent from my BlackBerry® wireless device

-Original Message-
From: Praveen Singh 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Thu, 29 Sep 2011 13:57:46 
To: 
Subject: [Tutor] where to look for python codes

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] guess age programme (please help)

2011-09-30 Thread bodsda
Hi,

I haven't checked your code because I am on my phone, but here is a tip for the 
loop condition

Use the guess in your loop condition e.g.

while guesses != 0:
Do stuff

That way, when guesses does equal 0, the loop condition will be false and 
therefore the loop will not run.
If you don't want to do that, look into the 'break' statement. 

while someOtherCondition:
Do stuff

if guesses == 0:
break



Hope this helps,
Bodsda 



Sent from my BlackBerry® wireless device

-Original Message-
From: ADRIAN KELLY 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Fri, 30 Sep 2011 12:04:58 
To: 
Subject: [Tutor] guess age programme (please help)

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] guess age programme (still stuck!!!!!)

2011-09-30 Thread bodsda
If I enter 35 at the prompt in your program, does python see
this: 35
Or
this: “35“
?

Hope this helps,
Bodsda
Sent from my BlackBerry® wireless device

-Original Message-
From: ADRIAN KELLY 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Fri, 30 Sep 2011 19:18:15 
To: 
Cc: 
Subject: Re: [Tutor] guess age programme (still stuck!)

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Input

2011-09-30 Thread bodsda
You could also use something like pygame to wait and test for keypresses

Bodsda
(Top post is phone limitation, sorry) 
Sent from my BlackBerry® wireless device

-Original Message-
From: Mark Lybrand 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Fri, 30 Sep 2011 13:27:27 
To: 
Cc: 
Subject: Re: [Tutor] Input

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Calling Python Functions from Powershell scripts

2011-10-05 Thread bodsda
You can run .py files from powershell, just like you would run any other 
command - 'python myfile.py'

I don't have any experience of the logging modules, but what I do when using 
multiple languages is have them all write to the same plain text log file and 
just prepend [] to the beginning of each line - that way I can 
track execution order and follow error/info messages all in one file.

That's just how I prefer to do it.

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: Nikunj Badjatya 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Wed, 5 Oct 2011 13:02:23 
To: tutor
Subject: [Tutor]  Calling Python Functions from Powershell scripts

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Job Scheduling package

2011-10-14 Thread bodsda
Have you thought about writing your own? Others have posted some useful links, 
but in all honesty you could hack something together to achieve that in next to 
no time

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: harish bansal 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Thu, 13 Oct 2011 15:23:04 
To: 
Subject: [Tutor] Python Job Scheduling package

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] printing a key not a value

2011-10-25 Thread bodsda
Sure,

mydict = {'a':1, 'b',2}
for key in mydict:
print key

Hope this helps,
Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: ADRIAN KELLY 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Tue, 25 Oct 2011 13:45:50 
To: 
Subject: [Tutor] printing a key not a value

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how can I save it from "for"

2011-11-11 Thread bodsda
Look into the 'continue' and 'break' statements - both very handy when working 
with loops

Or just increment/decrement the conditional until it evaluates to False

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: lina 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Sat, 12 Nov 2011 00:41:43 
To: tutor
Subject: [Tutor] how can I save it from "for"

Hi, I don't know how to escape the

if longest >= 3:
subgroup=S1[x_longest-longest:x_longest]
print(subgroup)

form the loop.


xrange = range

subgroup=[]
def LongestCommonSubstring(S1, S2):
M = [[0]*(1+len(S2)) for i in xrange(1+len(S1))]
longest, x_longest = 0, 0
subgroups=[]
uniq={}
for x in xrange(1,1+len(S1)):
for y in xrange(1,1+len(S2)):
if S1[x-1] == S2[y-1]:
M[x][y] = M[x-1][y-1]+1
if M[x][y] > longest:
longest = M[x][y]
x_longest = x
else:
M[x][y] = 0
if longest >= 3:
subgroup=S1[x_longest-longest:x_longest]
print(subgroup)


return S1[x_longest-longest:x_longest]


if __name__=="__main__":

for i in range(97,107):
for j in range(97,107):
if i != j:
LongestCommonSubstring(a,b)
'''LongestCommonSubstring(chr(i),chr(j))'''

Thanks ahead,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with error in ski game

2011-11-20 Thread bodsda
Just a guess but take a look at the spelling.

centerx
Or
centrex

Bodsda
Sent from my BlackBerry® wireless device

-Original Message-
From: Chloe Beck 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Sun, 20 Nov 2011 11:58:25 
To: 
Subject: [Tutor] Help with error in ski game

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ProgressBar - Python and Powershell

2011-11-20 Thread bodsda
This is just my opinion but I would have several (say 10) powershell scripts 
individually called by python, python will sit still until the powershell 
exits, then update the progress bar by 10% before calling the next script etc 
etc.

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Sun, 20 Nov 2011 08:00:43 
To: ; 
Subject: Re: [Tutor] ProgressBar - Python and Powershell

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Making a function run every second.

2011-11-29 Thread bodsda
You won't get it exactly on because the time it takes to call the function will 
affect your trigger time.

I would use something like an infinite loop with a 1 second sleep after the 
function call

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: "Mic" 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Tue, 29 Nov 2011 15:54:59 
To: 
Subject: [Tutor] Making a function run every second.

Hi

I want a function to run every second , how do I do that?

Say that the function look like this:

def hi():
print("hi")


Thanks! 


Mic
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to write lines in a text file (GUI)

2011-11-29 Thread bodsda
Hi,

This is a very simple objective to achieve, so instead of giving you a straight 
up solution, I will just nudge your train of thought in the right direction.

Note: I'm struggling to follow your code whilst reading on my phone so the 
following suggestions make no reference to your particular codebase

Let's first assume that all buttons could be pressed in any order, therefore 
given the following presses: but1, but2, but2, but3, we will have the first 
line with hi_1, the second line empty and the third line hi_3. Now I also 
assume that there is no 'update file' button, therefore each press of a button 
needs to update the file making a change to a single line. That sounds to me 
like a good use for an update_file function that accepts a parameter of which 
line should be updated. So the main challenge is to write a function that can 
read/write to a file certain data depending on the argument passed. The 
function should:

Read file
Identify line to be changed
If line empty
Change line to hi_#
Write file

When you open a file, you could then use the read function to read the whole 
file, or you could use the readlines function to read the file line by line. 
Experiment with both, see what data types they both return and decide which is 
most suitable. Bear in mind you need to easily differentiate each line and 
access them individually.

If your still struggling to write this function, show us how far you get and we 
can go from there.

Hope this helps,
Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: "Mic" 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Tue, 29 Nov 2011 19:02:52 
To: 
Subject: [Tutor] How to write lines in a text file (GUI)

Hey again.

I figured I would first post this piece of code and then ask my questions.

FREE = "green"
OCCUPIED = "red"

class Mainwindow(Frame):
 def __init__(self,master):
 super(Mainwindow,self).__init__(master)
 self.grid()
 self.create_mainwidgets()

 def create_mainwidgets(self):
 self.klicka=Button(self, text="Press the button",
command=self.uppdatera)
 self.klicka.grid()

 def uppdatera(self):
 SeatWindow(root)

class SeatButton(tk.Button):
 def __init__(self, master, index):
 text = str(index+1)
 super(SeatButton, self).__init__(master,
  text=text, bg=FREE,
  command=self.clicked)
 self.filename = "Germany_France{}.txt".format(index+1)
 self.occupied = False
 if os.path.exists(self.filename):
  self["bg"]=OCCUPIED

 def clicked(self):
 self.occupied = not self.occupied
 if self.occupied:
 self["bg"] = OCCUPIED
 text_file=open(self.filename,"w")
 text_file.write(self.filename)
 text_file.close()
 else:
 self["bg"] = FREE
 os.remove(self.filename)

class SeatWindow(tk.Toplevel):
  def __init__(self, master):
  super (SeatWindow, self).__init__(master)
  self.grid()
  self.create_widgets()

  def create_widgets(self):
  for index in range(20):
  button = SeatButton(self, index)
  row, column = divmod(index, 4)
  button.grid(row=row, column=column)

root=Tk()
root.title("testV2")
app=Mainwindow(root)
root.mainloop()




I am now writing another program. It turned out just fine, but I have one
question.

If button one is pressed I want the program to write, say hi_1, on the first
line in a text file.
If button one is pressed again, the first line should be empty.

If button two is pressed I want the program to write hi_2 in the second line
in the text file.
If button two is pressed again, the second line in the text file should be
empty.

If button three is pressed I want the program to write hi_3 in the third
line in the text file.
if button three is pressed again, the third line in the text file should be
empty.

There shouldn't be any other changes to the program other than this above.
There is already a text file
created, the program doesn't need to create one. We can call that file "Hi".


I hope you understand what I want to do here. I have tried the entire
evening yesterday to get this to work, I tried using writeline() but I can't
get it to work.
What are your suggestions to this?



Thank you for your help and time!

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to write lines in a text file (GUI)

2011-11-29 Thread bodsda
I'm not sure, I also don't have access to the python docs atm, but the simplest 
method would be to read the whole file into a list, edit the correct item 
(remembering to count from 0 not 1) and then writing the whole list back to the 
file.

Bodsda 
--Original Message--
From: Mic
To: bod...@googlemail.com
To: tutor-bounces+bodsda=googlemail@python.org
To: Tutor - python List
Subject: Re: [Tutor] How to write lines in a text file (GUI)
Sent: 29 Nov 2011 19:24



>Note: I'm struggling to follow your code whilst reading on my phone so the 
>following suggestions make no reference to your particular codebase

Okay I understand. Perhaps it doesn't matter.

>Let's first assume that all buttons could be pressed in any order, 
>therefore given the following presses: but1, but2, but2, but3, we will have 
>the first line with hi_1, the second line empty and the third line hi_3. 
>Now I also assume that there >is no 'update file' button, therefore each 
>press of a button needs to update the file making a change to a single 
>line. That sounds to me like a good use for an update_file function that 
>accepts a parameter of which line should be updated. >So the main challenge 
>is to write a function that can read/write to a file certain data depending 
>on the argument passed. The function should:

>Read file
>Identify line to be changed
>If line empty
>Change line to hi_#
>Write file

>When you open a file, you could then use the read function to read the 
>whole file, or you could use the readlines function to read the file line 
>by line. Experiment with both, see what data types they both return and 
>decide which is most >suitable. Bear in mind you need to easily 
>differentiate each line and access them individually.

>If your still struggling to write this function, show us how far you get 
>and we can go from there.

Actually, I nearly know how do to solve this problem. I just have one 
problem. Can I use writeline() to write text into line 3 or line 5 for 
example?
Say that I want to write the text "hi" into line five of a text file, can I 
do this using writeline(), if so, how ?

Thanks for the response!


Hope this helps,
Bodsda
Sent from my BlackBerry® wireless device


Sent from my BlackBerry® wireless device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list, tuple or dictionary

2011-11-29 Thread bodsda
You could use any of them, but a dict would be the most logical assuming no 
duplicate items

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: ADRIAN KELLY 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Tue, 29 Nov 2011 20:31:56 
To: 
Subject: [Tutor] list, tuple or dictionary

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Saved the Day

2011-12-04 Thread bodsda
We had a challenge recently where all of our internal department names changed, 
and due to our intranet system, we had to modify our Active Directory to 
reflect the new names. This meant changing all usernames, public drives and pc 
names. We were also migrating the profiles from one profile server to another 
at the same time.

A manual test run of our procedure determined a 6 hour process per depart. 
Worried for the strain this would have on my sanity, I spent 3 hours automating 
this process in python, cutting the execution time down to 30 minutes of 
watching success messages printing to the screen. This saved an estimated 55 
man hours of work.

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: wesley chun 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Sun, 4 Dec 2011 00:51:59 
To: Mark Lybrand
Cc: 
Subject: Re: [Tutor] Python Saved the Day

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unable to run file though dir path included

2011-12-06 Thread bodsda
This is only a guess, but when your typing 'python foo.py' the command prompt 
is looking for foo.py in its path and can't find it, then it throws the error.

When your in the interpreter, python has already updated its path so it can 
find your file.

I don't think adding the directory to 'python\Lib\Site-packages' is doing what 
you think it should do.

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: surya k 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Wed, 7 Dec 2011 00:27:30 
To: Python Tutor
Subject: [Tutor] unable to run file though dir path included

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Interprocess communication

2011-12-06 Thread bodsda
If you invoke the system 'cp' command though, it may not be possible to have a 
progress bar because the command will only talk back when it exits.

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: Alan Gauld 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Tue, 06 Dec 2011 19:04:01 
To: 
Subject: Re: [Tutor] Interprocess communication

On 06/12/11 17:17, George Nyoro wrote:
> Hey guys,
>Really want to thank all of you for helping and bearing with
> some of us and the questions we ask around here. I was making a gtk
> app sometime ago to copy files from a cd or dvd to my hard disk since
> the normal ubuntu copy thing would stop when it encountered some
> error, so I needed one that read through errors or none.

For me the normal copy thing is the cp command. It reads
through errors quite happily... I assume you mean one of
the graphical file managers abailable in Ubuntu?

> I did in two modules: one having gtk code and the other having the
> copy code, then id import the copy code into gtk. The thing is that
> when the gtk called the copy module to do so, the process would take
> long and so the application would become none responsive.

How are you doing the copy?
If its a long loop or using os.walk() then you need to put it in a 
separate thread. Thats probably the best solution. Alternartively invoke 
the cp command line and run it in the background(with &), but then you 
won;t get suvch good error reports etc...

Otherwise break it into chunks so you only copy a few files at a time 
and then return to the GUI. But that will slow the copy process even more!

>   Can anyone show me how to run the gtk and copy code as separate
> processes since this seems to be the only way that the application
> graphics wont hang? Thanks in advance.

You don't need separate processes just separate threads.
Check the Python documentation for a threading tutorial.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to find index of list with its value

2011-12-08 Thread bodsda
>>>mylist = [1,2,3,4,1]
>>>mylist.index(1)
0

But note that this only shows the index for the first occurrence of the item.

Bodsda 

Sent from my BlackBerry® wireless device

-Original Message-
From: surya k 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Thu, 8 Dec 2011 20:58:37 
To: Python Tutor
Subject: [Tutor] how to find index of list with its value


Well, we all know to know the value when we have the index of a list. But how 
can we find it in the reverse way...
say a listl=[1,2,3,4]
l[0]=1.but how can I find its address with its value 1 ??   
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list.index() question

2011-12-08 Thread bodsda
That won't work because l1[0] is ['a', 1]

What happens if you don't change the code?

l1.index('c')

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: Robert Berman 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Thu, 08 Dec 2011 16:13:32 
To: tutor
Subject: [Tutor] list.index() question

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] return, why do I need it?

2011-12-11 Thread bodsda
Why unindent functions for testing? 

Challenge: write a function called myadd(one, two) that accepts 2 parameters, 
both will be ints. When the function is called, it should add both parameters 
together.

It should allow me to do this:

a = myadd(5, 10)
a += myadd(10, 5)

a == 30
True

Hopefully that shows one usage of return values

Hth,
Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: "Pete O'Connell" 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Mon, 12 Dec 2011 01:08:47 
To: 
Subject: [Tutor] return, why do I need it?

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unsupported operand

2011-12-17 Thread bodsda
I would suggest a few things, like variable naming style consistency or the 
unused file that you open and close. You also have an unused lw variable, and 
does dpi really need to be a variable? Its only used once, why not hard code it.

But the main thing I suggest, is posting the 'complete' traceback, so we can 
see what caused the error. I'm gonna take a wild guess at it being the 
pyplot.plot call though, due to the data types that its moaning about.

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: stm atoc 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Sat, 17 Dec 2011 21:30:17 
To: tutor
Subject: [Tutor] unsupported operand

Hi there,

I would like to define concentration array based on time and then plot it.
Here is the profile:

from pylab import *
import numpy
import array
import math
tmax=1*3600
t  = 1.
outfile=open('ourtest_out.list','w')
N = 100
Conc1 = arange([0, tmax])
outfile.close()

lw = 2.0 #linewidth
dpi = 96
figure(figsize=(12,6),dpi=dpi)
pyplot.plot(Conc1, t,'r-',label='Conc' )
savefig('Conc.png')
show()

and this is the error that I got:

TypeError: unsupported operand type(s) for -: 'list' and 'int'

What would you suggest?
Thank you,
Sue
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A few Python Mysteries

2011-12-21 Thread bodsda
I think your missing the point. Ignore the fact that your PATH doesn't contain 
the correct paths to python.

The problem is that on startup, a program (unknown) is looking for the dll file 
for python2.5 - it is looking for this in the system32 directory. To be rid of 
the startup errors, you need to replace the dll that was removed by the 
uninstallation of python2.5 - to do this, reinstall python2.5

Bodsda 
Sent from my BlackBerry® wireless device

-Original Message-
From: Wayne Watson 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Wed, 21 Dec 2011 07:15:31 
To: Steven D'Aprano; tutor@python.org
Subject: Re: [Tutor] A few Python Mysteries

Python is long gone from my system.  I only have Python 27.  Somewhere a 
long the line, the uninstall of Python5 probably did not remove the 
Python5 from the PATH. I have no explanation as to why Python7 was not 
in the PATH.  I have no idea why some remnant of why Python6 is hanging 
around. I uninstalled it long ago too.

On 12/21/2011 2:43 AM, Steven D'Aprano wrote:
> Wayne Watson wrote:
>> I changed Python25 to Python27, and rebooted.  I got the same two dll 
>> msgs again.
>
> I suggest you find out what applications are trying to run using 
> Python 2.5. This is a Windows problem -- you need to get the list of 
> programs that run at start up and inspect them for something that uses 
> Python.
>
> Since I don't use Windows, I can't be more specific.
>
>
>

-- 
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

  (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
   Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

  CE 1955 October 20 07:53:32.6 UT
 -- "The Date" The mystery unfolds.

 Web Page:


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] re module help

2012-01-09 Thread bodsda
You could use read directly on the popen call to negate having to write to a 
file

output = os.popen(“sdptool -i hci0 search OPUSH“).read()

Bodsda
Sent from my BlackBerry® wireless device

-Original Message-
From: Ganesh Kumar 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Mon, 9 Jan 2012 14:47:46 
To: 
Subject: [Tutor] re module help

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with program from learning python the hard way

2012-01-19 Thread bodsda
If I say that sys.argv is a list, does that help you? 

Also, run things from a command prompt for this kind of thing, at least then 
you can guarantee what args get passed

Bodsda  
Sent from my BlackBerry® wireless device

-Original Message-
From: Jason Loeve 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Thu, 19 Jan 2012 15:02:41 
To: 
Subject: [Tutor] help with program from learning python the hard way

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor