rrashkin 41 Junior Poster in Training

I think there are 2 ways depending on just how big the file really is.

If it can all be read into memory, then I suggest:

        data=[]
        with open(<csv file name>) as fid:   
            lines=fid.read().split('\n')
        for i in lines: 
            data.append(i.split(','))
        data.sort(key=lambda x: x[3])
        for d in data:
            field=d[3]
            with open('pc_Numbers_'+field+'.csv') as fid:
                while d[3]=field: 
                    fid.write(d+'\n')

This assumes the field in question is in the fourth position (index 3).

If the file is really too big for this, then you'll have to read and write each line, changing the file name based on the field. Depending on how many files you expect, you may have to open and close them each time. That could make the program very slow.

rrashkin 41 Junior Poster in Training

It can be done with the eval() builtin function. However!!! it is very dangerous to allow users to input any old thing and then evaluate that input. It would be better to give them a limited set of choices.

rrashkin 41 Junior Poster in Training

Maybe:

with open('c:\FLOUpper.txt', 'r') as infile,open('c:\FLOLower.txt', 'w') as outfile:
    data = infile.readlines()
    data = [i.capitalize() for i in data]
    outfile.write(data)
Shaji_1 commented: Great starting point. Thank you! +0
rrashkin 41 Junior Poster in Training

get rid of "print(input(..."
name1=input("what is your name: ")

Gribouillis commented: indeed +14
rrashkin 41 Junior Poster in Training
>>> d={"key1":3,"key2":18,"key3":8}
>>> d["key2"]=0
>>> d
{'key3': 8, 'key2': 0, 'key1': 3}
>>> s=d.items()
>>> s
[('key3', 8), ('key2', 0), ('key1', 3)]
>>> for i in s:
...    if i[1]==0:
...       del d[i[0]]
... 
>>> d
{'key3': 8, 'key1': 3}
rrashkin 41 Junior Poster in Training

So you want to embed the second loop inside the first loop? That's not the way it is now.

rrashkin 41 Junior Poster in Training

Are you allowed to use list comprehension which is an implicit for loop?

[i*6 for i in xrange(3,0,-1)]
  [18, 12, 6]
rrashkin 41 Junior Poster in Training

I'm not sure how you're supposedto use re.finditer but not this way. The elements of the returned list are match objects, not strings. I suggest you use findall instead. If I do this:

 lst1=re.findall(r'rhs="(.*)"',d1)

I get this:

['domain.com', 'domainn.com', '1010data.com']
rrashkin 41 Junior Poster in Training

You have: from tkinter import *.
Should be: Tkinter

rrashkin 41 Junior Poster in Training

random.choice() will return a single element. Why are you making it a tuple? If you are trying to get the key and value out, you will need to do it explicitly:
k=random.choice(d_mod); v=d_mod[k]; arr[y].append([k,v])
if that's what you really want.

rrashkin 41 Junior Poster in Training

You print the index after the value is incremented:

        index += 1
        print "index: " +str(index)

So the loop is iterated with the value of "index" equal to 11, then the value of index is increased but the loop is not evaluated so the processing doesn't cease.

rrashkin 41 Junior Poster in Training

I'm guessing it's "wind direction"

rrashkin 41 Junior Poster in Training

Let's say d is a date string in the format you posted. Then
m=datetime.date(*map(int,d.split("/"))).month
returns the month as an integer. You could construct a dictionary that collects the data for each month:
dctTemp[m].append(newTemp)

Then you can average the values when you collect all the days.

rrashkin 41 Junior Poster in Training

I've used both and I make my decision as follows: I use Tkinter on Windows since Python installs with it and I use GTK on Linux (Ubuntu) since that's what comes with that.

rrashkin 41 Junior Poster in Training

First of all, you probably don't need to close and open "writer" at every step. It's just creating a lot of overhead. Open it once as you do before the loop and close it once afterward.
As for the reading files, instead of writer=open('psub', 'a'), which I recommend you remove, put reader=open(files) (open for reading is the default). Then change the close to reader.close().

rrashkin 41 Junior Poster in Training

Within the function, you do, indeed, need to initialize y before you can start defining elements. Even then, if you try to assign elements out of order, that is, an element, [i], when [i-1] is empty, you will get the out of range error:

>>> y=[]
>>> y[8]=5
Traceback (most recent call last):
  File "/base/data/home/apps/runpythoncode/103.348367701639469596/console.py", line 123, in _execStatement
    exec compiled in statement_module.__dict__
  File "<string>", line 1, in <module>
IndexError: list assignment index out of range

You can initialize the y list with blanks before you start the loop with list comprehension:

y=[" " for i in xrange(len(x))]

or by list multiplication:

y=len(x)*[" "]
rrashkin 41 Junior Poster in Training

I'm guessing you're using Python 3.x where print() takes exactly one argument. Instead of print (x)('x')(y) you need something like ("something like" because I don't have Python 3 to test on): print(x + 'x' + y)

rrashkin 41 Junior Poster in Training

Can you assume that each word is separated by a space (one and only one), and that there are no leading and trailing spaces? If so, let's say your list of strings is "list-1". Then you could make a list of word counts as: list-2=[i.count(" ")+1 for i in list-1]
Then the max word count is: max(list-2),
and the string in list-1 with that count is: list-1[list-2.index(max(list-2))]

rrashkin 41 Junior Poster in Training

I would start by reading the file into a list:

fid=open('file1.txt')
lstData=fid.readlines()
fid.close()

Now the last record is: lstData[-1]

To loop through the records from the 2nd to last until the first,
for i in lstData[-2::-1]:

rrashkin 41 Junior Poster in Training

I'm not really clear what you're trying to do but os.system has fallen from favor and the subprocess module is recommended. Maybe that will suit your needs better.

james.lu.75491856 commented: WRONG! os.system for all the commands in command line! not for launching programs! +0
Gribouillis commented: indeed +14
rrashkin 41 Junior Poster in Training

sure. It's just a name.

rrashkin 41 Junior Poster in Training

look at this for an example. Basically, the key is in the open():

Modes 'r+', 'w+' and 'a+' open the file for updating (note that 'w+' truncates the file). Append 'b' to the mode to open the file in binary mode, on systems that differentiate between binary and text files; on systems that don’t have this distinction, adding the 'b' has no effect.

rrashkin 41 Junior Poster in Training

Well, when you set enemy equal to goblin, that's really just an association, not a new object. You can see an explanation of the issue and the use of "copy" to deal with it here. Perhaps it is simpler just to instantiate a new obect.

rrashkin 41 Junior Poster in Training

This is sort of buried in the language reference. If you look here: Click Here, it gets explained, but you have to dig. In particular:

or passed as a value in a dictionary preceded by **

That means that the identifier after the "**" is a dictionary with "variable name: value" entries.

rrashkin 41 Junior Poster in Training

The maximum height is where yvel = 0. In your initialization method you have:
self.yvel=velocity*sin(theta)
You know that yvel goes to zero when 0.98*time equals the initial velocity, or at
velocity*sin(theta)/9.8 seconds
So you can figure out when you get to that time at your interval.
Now since xvel is presumed not to change, the xpos at that time is
(velocity*sin(theta)/9.8)*velocity*cos(theta)

rrashkin 41 Junior Poster in Training

So what's the question? The keys are names and the values are strings.

rrashkin 41 Junior Poster in Training

I would need more information to answer that. What is the structure of the dictionary? Normally, I would key an address book on "name" so something like AddBook={"john doe":("8134789 Zubruzlechester", "Alpha Centauri", "999-555-1234")}. In that case I would get the telephone number, for instance, for John Doe, as: AddBook["john doe"][2]

rrashkin 41 Junior Poster in Training

check out the pickle module (I think it still is used with v3.x)

rrashkin 41 Junior Poster in Training
colorcode="#00ffaa"
strBase1="blah blah blah kjklajaskladfjlkjasdf maxMass="
strBase2="blah blah aiopweruioweruio minMass="
strBase3="blah blah iqweuiqweru890 colorCode="
strBase4="2389023489asdfjkl qwruijasdfjklha fasdfasdf"
chrDelim=","
f1=open(<input file name>)
f2=open(<output file name>,"w")
for strLine in f1:
    lstLine=strLine.strip('\n').split(chrDelim)
    colorcode=colorcodefunction(lstLine)
    strOut=strBase1+lstLine[0]+strBase2+lstLine[1]+strBase3+colorcode+strBase4
    f2.write(strOut+'\n')
f1.close()
f2.close()
rrashkin 41 Junior Poster in Training

My question really was after you identify a duplicate (never mind for now how you do that), then you have 2 records with the same, let's say, email field value. What next? Do you write both records to the new file? Just one (which one)?

rrashkin 41 Junior Poster in Training

When you identify a duplicate, let's say there are 2, do both get written to the file or just the one that wasn't first?

rrashkin 41 Junior Poster in Training

I think this is the culprit: Resistance.append(tuple((float(x) if x.strip() else '0.0'). On the one hand it's number, on the other, a string.

rrashkin 41 Junior Poster in Training

Well, I'm sure with polynomial recursion you can make it as complicated as you need to but if we take every 2 points on the reference track to define a line, then you can define a parallel line that is offset from that as I described above. Then you just do that for every point pair. It's tedious but that's why we have computers.

Gribouillis commented: I agree with that +13
rrashkin 41 Junior Poster in Training

Let's forget the altitude component for now since I don't think you're really mapping in 3-d here. So you have a series of lat/long. Let's say you know how to convert that to a more convenient x/y system. Now, if your track is a straight line, then you can easily turn it into a parametric representation: y=mx+b where m is the slope (δy/δx) and b is the y-intercept. Then a parallel line has the same m and an offset (+ or -) of b. Is your track straight? If not, is it piece-wise straight?

rrashkin 41 Junior Poster in Training

You've got the right idea but I think you're doing something you don't want to do and I know you're doing something wrong.

First the wrong thing.
When you read each line, for line in f.readlines():, "line" is a string. Strings are iterable but each character is an element. So, line[0] for instance would be "5" in the case of the Bart Simpson record. To get what you want you need to split the line into words (splitting on spaces): line=line.strip('\n').split(), also taking off the linefeed. Now you have another problem, the "name" field is 2 words, line[1] and line[2]. If you know both names are always going to be present then you can use the constructor: Persons(line[0], line[1]+' '+line[2], line[-1]). Otherwise you'll need to check on how many elements line has 4 or 3 and construct the object accordingly.

Now the other thing. In your loop, you keep using the same object name, "pers". Once the loop is done, you'll only have a single object. There are lots of ways to keep all the people "alive" but I think the best is to have a dictionary of people, dctPerson={}, and instead of "pers" use dctPerson[line[0]]=Persons(line[0], line[1]+' '+line[2], line[-1]).

rrashkin 41 Junior Poster in Training

oops. that should be "set_address(self,address)"

rrashkin 41 Junior Poster in Training

Think about it like this:
when you set "self.address=address", you are assigning a value to an attribute. If that were inside a method, say, "set_address(address)" and looked exactly the same, would that be what you wanted?

Also, your "get_name" method is wrong, I think. There is no attribute defined to be "_name".

rrashkin 41 Junior Poster in Training

You need to
1 - remove the linefeeds from the input line (line=line.strip('\n'))
2 - split the line into a list (lstLine=line.split(','))

rrashkin 41 Junior Poster in Training

Look. It's a bit presumptuous, if not rude, to ask people to do your homework without even making a token attempt, yourself. Do you have any code written? Do you understand classes/objects at all in some other context maybe?

Think of it this way:
There is a class, "patient". Objects in that class have some attributes: age, weight, sex, dob, name, ID, address, phone number.

class patient():
      def __init__(self, ID, name, dob, sex, phonenumber, address):
          self.ID=ID
          self.address=address

bob=patient("0012","bob","8/8/88","m","888-8888","888 Oak")
rrashkin 41 Junior Poster in Training

change z = setup.readline()
to z = setup.readline().strip('\n')

rrashkin 41 Junior Poster in Training

What graphics module are you using? In Tkinter, there is nothing called an input box. Rather there is a widget called an "entry". It has no title, but you can fit it with a "label". Likewise, pyGTK, has a "text" and "label". In non-GUI python, "input" is a command indicating that the user is expected to type text. There's no box and no title. So, maybe I'm just not getting something obvious about your question but I'm not.

rrashkin 41 Junior Poster in Training

I think the csv module is overkill for most applications. I'm not sure I follow what the format of your data file is but let's say each line in the CSV file has n fields separated by ";". Depth is in field i (starting from 0), time is field j, and temperature is field k (you can substitute the real values (0,1,2?) as you probably know them).

depth=[]
time=[]
temp=[]
csvf=open(<filename>)
csvf.readline() #to get past the first row (headers)
for r in csvf:
  lstr=r.split(";")
  depth.append(lstr[i])
  time.append(lstr[j])
  temp.append(lstr[k])
csvf.close()
rrashkin 41 Junior Poster in Training

A dictionary isn't really a natural implementation of a database. I suppose you could have each row be it's own dictionary such that row1={key1:value1, key2:value2,...} and likewise for all rows. Then you'd get the value in column3, row3 from row3[key3] or something like that. I think a better implementation is just to use a list of lists where the first element is a list of column headings.