Use GUI for Python
I am new to python as I have been a VB programmer. I am used to the GUI interface, and was wondering if I had to choose between a GUI for Python, which one should I go with? Thanks. Kou -- http://mail.python.org/mailman/listinfo/python-list
Newbie question
If I have a file name: AVC1030708.14. How do I strip out certain characters from the file name? I am so used to using MID, LEFT, and RIGHT functions, that I have no idea how to do this in python? I have had trouble as well with most newbies on finding the help. But I have used the command line built in help, but with no luck. Thanks. Kou -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question
On Sep 18, 1:31 pm, "Shawn Milochik" <[EMAIL PROTECTED]> wrote: > On 9/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > If I have a file name: AVC1030708.14. How do I strip out certain > > characters from the file name? I am so used to using MID, LEFT, and > > RIGHT functions, that I have no idea how to do this in python? I have > > had trouble as well with most newbies on finding the help. But I have > > used the command line built in help, but with no luck. Thanks. > > > Kou > > Do you want to strip out specific characters, characters in specific > positions, or characters matching certain patterns? Yes, I want specific characters in specific positions. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question
On Sep 18, 1:42 pm, "Shawn Milochik" <[EMAIL PROTECTED]> wrote: > On 9/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > > > > On Sep 18, 1:31 pm, "Shawn Milochik" <[EMAIL PROTECTED]> wrote: > > > On 9/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > > If I have a file name: AVC1030708.14. How do I strip out certain > > > > characters from the file name? I am so used to using MID, LEFT, and > > > > RIGHT functions, that I have no idea how to do this in python? I have > > > > had trouble as well with most newbies on finding the help. But I have > > > > used the command line built in help, but with no luck. Thanks. > > > > > Kou > > > > Do you want to strip out specific characters, characters in specific > > > positions, or characters matching certain patterns? > > > Yes, I want specific characters in specific positions. > > Try this: > > newString = oldString[0:3] + oldString[5:10] > > Some other quick examples: > > >>> test = "this is a test" > >>> test > 'this is a test' > >>> fred = test[:3] + test[9:] > >>> fred > 'thi test' > >>> test[0:5] > 'this ' > >>> test[:5] > 'this ' > >>> test[4:] > > ' is a test'- Hide quoted text - > > - Show quoted text - I see. It's so hard to imagine the world of python than from VB. It's like looking at VB is in 2 dimensions, where with Python, it's more 3D. The code is so simple, yet it's hard for me to envision how to do something so simple. I guess it's because the rules or the way of looking at things in Python, things can be stripped down to the bare bones and in so many ways. Thanks. Kou -- http://mail.python.org/mailman/listinfo/python-list
How do you limit the # of lines Read?
I am working on a loop for my code and was wondering if there is a way to limit the number of lines read through? I'd hate to cut the test file in order to run the code in the testing phase. Can you add a value in the parenthesis of the readline() function? t = string.readline() # Limit this somehow? Kou -- http://mail.python.org/mailman/listinfo/python-list
Lookup values from one table to another based on a value
If I wanted to accomplish looking up values from one table based on a value from another table or file, how would I go about doing this in Python? Would I build a dictionary or an array? exp: Table1: Site = 103 Lane = 2 Dir = ? # Get this from Table2 Table2: Site, Lane, Direction, 103, 1, 1 103, 2, 1 103, 3, 5 103, 4, 5 Normally in Access I would just use a Dlookup and be done with it, or use a Recordset in VB. Thanks guys. Kou -- http://mail.python.org/mailman/listinfo/python-list
Re: Lookup values from one table to another based on a value
On Sep 20, 10:34 am, Bruno Desthuilliers wrote: > [EMAIL PROTECTED] a écrit : > > > > > > > If I wanted to accomplish looking up values from one table based on a > > value from another table or file, how would I go about doing this in > > Python? Would I build a dictionary or an array? > > > exp: > > > Table1: > > > Site = 103 > > Lane = 2 > > Dir = ? # Get this from Table2 > > > Table2: > > > Site, Lane, Direction, > > 103, 1, 1 > > 103, 2, 1 > > 103, 3, 5 > > 103, 4, 5 > > > Normally in Access I would just use a Dlookup and be done with it, or > > use a Recordset in VB. Thanks guys. > > What about using a database ? Like SQLite ? > > Else, the canonical data structure for quick lookups is of course the dict.- > Hide quoted text - > > - Show quoted text - Ah, yes, that would appear to be a better means to retrieve data. I visited the site, which version should I download? Thanks. Kou -- http://mail.python.org/mailman/listinfo/python-list
Re: Lookup values from one table to another based on a value
On Sep 20, 11:51 am, Bruno Desthuilliers wrote: > [EMAIL PROTECTED] a écrit : > > > On Sep 20, 10:34 am, Bruno Desthuilliers > [EMAIL PROTECTED]> wrote: > >> [EMAIL PROTECTED] a écrit : > (snip) > >>> Normally in Access I would just use a Dlookup and be done with it, or > >>> use a Recordset in VB. Thanks guys. > >> What about using a database ? Like SQLite ? > > > Ah, yes, that would appear to be a better means to retrieve data. I > > visited the site, which version should I download? Thanks. > > The latest, unless you have reasons to choose an old one !-) If I flipped the Table being looked up not to repeat, would that make things easier to look up a value in? Exp: Table1 Site = 103 Lane = 1 Direction = ? FHWA Lane = ? Table2 Site, Lane 1, Direction 1, FHWA Lane 1, 103, 1, 1, 1 -- http://mail.python.org/mailman/listinfo/python-list
Nested For and While Statements
I start my code with some constants then a while statement. But I have some For statements towards the end within the While statement where I start getting some errors. I'm hoping I won't have to post my code, but it looks something like this: Import os, string while this: All Code indented like it should Last line in While. For i in range(1) class = [] class2 = [] For i in range(2) Do this And this And that. Next Line hits snag here? Where should this line be? -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested For and While Statements
On Sep 24, 3:01 pm, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Sep 24, 2:28 pm, [EMAIL PROTECTED] wrote: > > > > > > > I start my code with some constants then a while statement. But I > > have some For statements towards the end within the While statement > > where I start getting some errors. I'm hoping I won't have to post my > > code, but it looks something like this: > > > Import os, string > > > while this: > > > All Code indented like it should > > > Last line in While. > > >For i in range(1) > > class = [] > > class2 = [] > > For i in range(2) > > Do this > > And this > > And that. > > > Next Line hits snag here? Where should this line > > be? > > Why are the for loops further indented than the body of the while? If > they are part of the while, "For i in range(1)" should line up with > "Last line in While." If they are not part of the while, but come > after, then "For i in range(1)" should line up with "while this:". > > Also, as James Stroud said, your for loop indexes are the same > variable. > > -- Paul- Hide quoted text - > > - Show quoted text - My actual code has different variables, but thanks for pointing that out. I'm so used to coding in VB, where indenting isn't a problem, so all this indenting is new to me how Python wants it dictated. I made the changes and still get an error at the same point after the second For statement? So: While : Code under while More under while. For (x) Part of x Last of x For(y) Part of y Still part of y last part of y. New line part of x #where does this belong? Last line under while not in For #Should go under While, right? If I want all my code to run under the while, then the While statement should be the only line of code not indented once I state it then, correct? -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested For and While Statements
On Sep 24, 3:44 pm, Roberto Bonvallet <[EMAIL PROTECTED]> wrote:
> On Sep 24, 3:28 pm, [EMAIL PROTECTED] wrote:
>
> > [...] where I start getting some errors.
> > I'm hoping I won't have to post my code
>
> "Doctor, I'm feeling bad. I hope I won't have to tell you my
> symptoms. What do I have?"
>
> Please provide the actual errors and the actual code. It is easier,
> less error prone and more useful to copy and paste them instead of
> writing some pseudocode. Maybe the repeated index i is a typo you
> made when writing this post and the original code is correct, but we
> don't have any way to know that.
>
> --
> Roberto Bonvallet
Here is my code, in the hopes that there is a reason why it isn't
running. Thanks guys.
Option Explicit - 'Sorry so use to writing this!
import os, string
# Get filename to work with
workspace = "c:\\temp"
filename = "\AVC1030708.14"
doc1 = workspace + filename
onedoc = open(doc1, "r")
rdoc1 = onedoc.read()
doclist1 = string.split(rdoc1, "\n")
for i in range(8):
doclist1.pop(0)
length = int(len(newlist1))-2
Nscheme = int(filename[12:14])
numlanes = length/Nscheme
site = filename[4:7]
year = filename[7:9]
month = filename[9:11]
Sscheme = str(Nscheme)
# Get Master AVC Table for Lanes & Direction
fileavc = "\AVCMaster"
doc2 = workspace + fileavc
twodoc = open(doc2, "r")
rdoc2 = twodoc.read()
doclist2 = string.split(rdoc2, "\n")
doclist2.pop(0)
# Dictionary of Zeros to add to Class Fields
addzeros = {1:"0", 2:"00", 3:"000", 4:""}
while doclist1:
list1 = doclist1[0]
doclist1.pop(0)
newlist1 = list1.split(",")
date1 = newlist1[0]
if len(newlist1[0])== 8:
day = date1[2:3]
else:
day = date1[2:4]
if len(day)>1:
day = "0" +1
hour = newlist1[1]
lanex = []
# Find number of Lanes & Fields
if numlanes == 2:
lane1 = newlist1[2:2+Nscheme]
lanex.append(lane1)
lane2 = newlist1[2+Nscheme:2+Nscheme*2]
lanex.append(lane2)
else:
lane1 = newlist1[2:2+Nscheme]
lanex.append(lane1)
lane2 = newlist1[2+Nscheme:2+Nscheme*2]
lanex.append(lane2)
lane3 = newlist1[2+Nscheme*2:2+Nscheme*3]
lanex.append(lane3)
lane4 = newlist1[2+Nscheme*3:2+Nscheme*4]
lanex.append(lane4)
doctemp = doclist2
listtemp = doctemp[0]
avclist = listtemp.split(",")
while site <> avclist[0]:
doctemp.pop(0)
listtemp = doctemp[0]
avclist = listtemp.split(",")
dirx = []
fhlanex = []
dirx.append(avclist[2])
fhlanex.append(avclist[3])
dirx.append(avclist[5])
fhlanex.append(avclist[6])
if avclist[8] <> "0":
dirx.append(avclist[8])
fhlanex.append(avclist[9])
dirx.append(avclist [11])
fhlanex.append(avclist[12])
for x in range(1, numlanes+1):
avcclass = []
Nlanex = []
for i in range(1,Nscheme+1):
numzeros = 5 - int(len(lanex[i-1]))
avcclass.append(addzeros[numzeros] + lanex[i-1])
Nlanex.append(int(lanex[i-1])
lanex.pop(0)
totalclass = sum(Nlanex)
Stotalclass = str(totalclass)
#Create 90 Character File for SAS Job
classsum = avcclass[0] + avcclass[1] + avcclass[2] +
avcclass[3] + avcclass[4] + avcclass[5] \
+ avcclass[6] + avcclass[7] + avcclass[8] + avcclass[9] +
avcclass[10] \
+ avcclass[11] + avcclass[12] + avcclass[13]
classmn = "C27" + site + dirx[x] + lanex[x] + year + month +
day + hour + Stotalclass + classsum
break
avcsasdoc = workspace + "\avcsas.txt"
fdoc = open(avcsasdoc, "w")
fdoc.write(classmn)
--
http://mail.python.org/mailman/listinfo/python-list
Delete values from a string using the index
How do I delete or remove values from a list or string using the index. If a = [1,2,3,4,5,6,7,8] and I want to get rid of 1 -5, how would I do that? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
True of False
I tried writing a true and false If statement and didn't get anything? I read some previous posts, but I must be missing something. I just tried something easy: a = ["a", "b", "c", "d", "e", "f"] if "c" in a == True: Print "Yes" When I run this, it runs, but nothing prints. What am I doing wrong? Thanks. Kou -- http://mail.python.org/mailman/listinfo/python-list
Delete spaces
If I have a text file that is delimited by spaces, how do I import it and get to comma delimited? Here is a row of data from the text file: 1110:55:14 265 8.5 1.4+1.1 2.5 Class-2 0 I tried a few examples from the group and it didn't work, since the file also has a header row and a row of seperators ( ---). The lengths of each row is something like 130, so there are extra spaces after the last value as well. I have tried joining and other things, but I couldn't figure out how to get the values to come together. Thanks. Kou -- http://mail.python.org/mailman/listinfo/python-list
display messages in python shell
Is it possible to display messages in the python shell? I want to display error messages based on parameters in my scripts to the users. Is there another way to display messages other than log files? Thanks. Kou -- http://mail.python.org/mailman/listinfo/python-list
Writing Error in program
I have a code that writes to 2 seperate files. I keep getting a "list index out of range" error. The strange part is that when checking the files that I'm writing too, the script has already iterated through and finished writing, yet the error stated implies that it hasn't? So how can it be, that my script has written to the files, yet the error is stating that it hasn't made it through the script? I'll have 15 files that I have written to and the script will bog out at number 10? Is python doing something I'm not seeing? I printed everything that was written on the shell and it shows that it went through the script, so how can it still say there are a few files left to iterate through? -- http://mail.python.org/mailman/listinfo/python-list
