Beat_Slayer 17 Posting Pro in Training

Like this?

for item in fenceLines:
    print item

or

for i in range(len(fenceLines)):
    print fenceLines[i]

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

An if ... elif ... elif ... sequence is a substitute for the switch or case statements found in other languages.

Source

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

It depends a lot of the application, and all of that.

But maybe a simple http server or json server in a peer to peer configuration should serve the task pretty good.

I''ve never tried xmlrpc servers, since I never felt the need to.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training
relevant_weeks = [['[11', " '05/10/2009'", " '06/10/2009'", " '07/10/2009'", " '08/10/2009'", " '09/10/2009']", ''],
                  ['[10', " '28/09/2009'", " '29/09/2009'", " '30/09/2009'", " '01/10/2009'", " '02/10/2009']", ''],
                  ['[27', " '25/01/2010'", " '26/01/2010'", " '27/01/2010'", " '28/01/2010'", " '29/01/2010']", '']]

relevant_days = ['TUES', 'TUES', 'THURS', 'WED', 'THURS', 'MON', 'WED', 'THURS', 'WED', 'TUES', 'MON', 'WED', 'MON', 'WED', 'THURS', 'FRI', 'THURS']

days_reference = [['0', ' MON', ' TUES', ' WED', ' THURS', ' FRI']]

days_reference = [item.strip() for item in days_reference[0]] # cleaning the list


for i in range(len(relevant_weeks)):
    print relevant_weeks[i][days_reference.index(relevant_days[i])]

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Seems fun but I don't understand.

Can you explain?

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training
else:
    infos = [item for item in fields[i] if item]
    f_out.write('%s,%s,%s\n' % (pre, infos[0], infos[1]))

This is for lines like: ,,,"bonapartei","Highland Tinamou"

it extracts the two fields and writes them together with the prefix, that is get by lines like: ,,"Tinamus",,

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Like this mate:

list1 = ['a', 'b', 'c']

for i in range(len(list1)):
    open('file%s.txt' % i, 'w').write(list1[i])

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training
import re

data = 'LUBS5200M01/SMR 1/02<S1> wks 2-11,"((10 11 12 13 14 15 16 17 18 19) (34))",2'

data = data.split(',')[1]

match = re.findall(r'\(\d+\)', data)

print match[0][1:-1]

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

That means that you have a typo, or your reference list is somenthing like:

reference_list = '1, 2, 3, 4'

and for that:

reference_list = [int(item.strip()) for item in reference_list.split(',')]

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training
f_in = open('mixorder.csv')

fields = []

for line in f_in.readlines():
    fields.append([item.strip('\n') for item in line.split(',')])

f_in.close()

f_out = open('order.csv', 'w')

for i in range(len(fields)):
    if fields[i][0] != '':
        f_out.write('ORDRE ' + fields[i][0] + ',,\n')
    elif fields[i][1] != '':    
        f_out.write('Family ' + fields[i][1] + ',,\n')
    elif fields[i][2] != '':
        pre = fields[i][2]
    else:
        infos = [item for item in fields[i] if item]
        f_out.write('%s,%s,%s\n' % (pre, infos[0], infos[1]))

f_out.close()

Cheers and Happy coding


EDIT: I didn't saw your posted solution tonyjv.

Beat_Slayer 17 Posting Pro in Training

Hint:

list1 = [4, 3, 1, 3, 2, 1] 

list2 = [[0, '0800', 'MON'],
         [1, '0830', 'MON'],
         [2, '0900', 'MON'],
         [3, '0930', 'MON'],
         [4, '1000', 'MON']]

for i in range(len(list1)):
    for item in list2:
        if item[0] == list1[i]:
            print item

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

The error message you receive helps who is trying to help you. Try to post it next time.

But, since your error is easy, here it goes:

def lvl():
    x = random.randint(100,1000)
    tfile = open("text.txt", 'w')
    tfile.write(str(x))
    input("")

Cheers and Happy coding.

Beat_Slayer 17 Posting Pro in Training

Whats your line 6?

And shouldn't you have

lstn.recv(1)

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

One hint.

import time

date = 19980224
print time.strptime(date, '%Y%m%d')

date = 19982402
print time.strptime(date, '%Y%m%d')

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

??? Something is wrong here.

Can you show code to what you do?

You can't receive or send data through a socket if you properly closed it.


Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Going from the root as as folder python,

python\Objects\intobject.c

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Like this?

f_in = open('ids.txt')

for line in f_in.readlines():
    print line
    pos = 0
    for run in range(line.count('ID=')):
        pos = line.index('ID=', pos) + 3
        print line[pos:pos + 4]

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Some code to see what you have done so far so we can guide you?

Cheers and Happy coding.

Beat_Slayer 17 Posting Pro in Training

Why not?

top10 = [
        [[u'abcde', u'fghij'], [1]],
        [[u'abcde', u'fghij'], [2]],
        [[u'abcde', u'fghij'], [3]],
        [[u'abcde', u'fghij'], [4]],
        [[u'abcde', u'fghij'], [5]]]

top10 = [[[str(a), str(b)], x] for [a, b], x in top10]

for item in top10:
    print item
Output:
[['abcde', 'fghij'], [1]]
[['abcde', 'fghij'], [2]]
[['abcde', 'fghij'], [3]]
[['abcde', 'fghij'], [4]]
[['abcde', 'fghij'], [5]]

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

I did nothing to the code mate, I just showed you a part of your code where within 5 lines you call two different things to the 'same' variable.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Has nothing to do with putting 'self.' on front of everything, but at least being coinsistent on the variables. Look here:

def onAction(self, event):
    disc_value = self.discountinput.GetValue().strip()
    if all(x in "0123456789.+-" for x in disc_value):
        value = round(float(disc_value), 2)
    else:
        discountinput.ChangeValue("number only")

Is it discountinput, or the discountinput from the class (self.discountinput)?

When you declare a class yes define attributes to the class by wirting them as 'self.'.

If you don't declare them as attributes you may not call them as attributes.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Happy coding mate.

Case solved. You can close the thread.

Beat_Slayer 17 Posting Pro in Training

Change also your line 21 mate.

Cheers and Happy coding.

Beat_Slayer 17 Posting Pro in Training

You must use

self.cursor = db.cursor()

Then the LoginDld will have the cursor attribute, replace on all cursor declarations on the logiDlg and try again.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

You can declare the cursor as:

self.cursor = db.cursor()

and call it as:

login = LoginDlg()

login.cursor.execute('sql statement')
Beat_Slayer 17 Posting Pro in Training

The connection is available till you do a db.close() I believe, but I never used MySQL.

Beat_Slayer 17 Posting Pro in Training

Post some code, it should be easy to try to correct.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

A example:

print item.lower()

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Why the use of break or continue for the purpose??

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Deleted the last three lines of the login.py and it works.

Your login.py only may not be written as an actual script.

Cheers and Happy coding.

Beat_Slayer 17 Posting Pro in Training

This simple solution will work for all files on the current dir.

import os

filelist = os.listdir('')

for files in filelist:
    basename, ext = os.path.splitext(files)
    if ext == '.kml':
        f_output = open('%s-errors.txt' % basename, 'w')
        f_output.write('whatever you want')
        f_output.close()

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

And how are you implementing it?

Beat_Slayer 17 Posting Pro in Training

Doesn't this work?

from login import LoginDlg
Beat_Slayer 17 Posting Pro in Training

I think that definatelly it's a bad version installed.

Try to redownload and install the proper ones.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

You must understand the question and logics first.

And as lrh9 said, and very good, you declare classes and define their functions.

class rectangle():

    def __init__(self, coords, sizex, sizey):
        self._startx, self._starty = coords
        self._sizex = sizex
        self._sizey = sizey

    def getBottomright(self):
        print '(%s, %s)' % (self._startx + self._sizex, self._starty + self._sizey)

    def move(self, pos):
        self._startx, self._starty = pos

    def resize(self, width, height):
        self._sizex = width
        self._sizey = height

    def __str__(self):
        return '((%s, %s), (%s, %s))' % (self._startx, self._starty, self._startx + self._sizex, self._starty + self._sizey)


r = rectangle((2, 3), 5, 6)
print str(r)

"""'((2, 3), (7, 9))'"""

r.move((5, 5))
print str(r)

"""'((5, 5), (10, 11))'"""

r.resize(1,1)
print str(r)

"""'((5, 5), (6, 6))'"""

r.getBottomright()

"""(6, 6)"""

Cheers and Happy coding.

Beat_Slayer 17 Posting Pro in Training

I get it now.

Here it is. All you need. Classes

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Some code and a clear explanation of the problem you have would help.

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Mate, I believe that all you need to do, it's to use my example of timer, and use it to call the function to voice, instead of the threading being the voice function, the thread will calll the object voice after that time.

Hope is clear enough.

Cheers and Happy coding.

Beat_Slayer 17 Posting Pro in Training

It was a tip as I said, and you can read the lines individually as he does now.

And your code still uses my 60 GB+ RAM stick. :)

Beat_Slayer 17 Posting Pro in Training

A tip:

for line in in_file.readlines():

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

It's a typo. Your missing a d here.

elif option == 2:
    remove[B]d[/B]Expence = removeExpence(totalBudget)
    totalBudget = totalBudget + removedExpence
    printOptions()
    option = input("What would you like to do? ")
Beat_Slayer 17 Posting Pro in Training

The 'blit' loads a image object to the window surface.

In your example 'blit' loads the 'background' image to the window starting at cordinates 0 in x and 0 in y.

screen.blit(background, (0, 0))

The second 'blit' loads the 'sprite' image to the screen, with a fixed cordinate of 100 in 'y', and uses a variable 'x' to define the cordinate on x, that is incremented by 10 every cycle.

screen.blit(sprite, (x, 100))
x += 10

Hope it helps,

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

If i understood correctly:

initial_date = '9/14/1990'
initial_month, initial_day, initial_year = initial_date.split('/')
final_date = '9/17/1990'
final_month, final_day, final_year = final_date.split('/')

f_in = open('stations_temp.csv').readlines()
f_out = open('filtered_stations_temp.csv', 'w')

f_out.write(f_in[0])

for i in range(1, len(f_in)):
    station, date, max_temp, min_temp = f_in[i].split(',')
    month, day, year = date.split('/')
    if initial_month <= month <= final_month and \
    initial_day <= day <= final_day and \
    initial_year <= year <= final_year:
        f_out.write(f_in[i])

f_out.close()

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

I don't get the previous link.

May you take a look here, fell free to ask, or PM with sugestions.

Texts K-Nearest Neighbor (KNN) using the Euclidean algorithm

Beat_Slayer 17 Posting Pro in Training

Something like this.

name = []
ordertotal = []
for i in range(loopController):
    name.append(raw_input("Who's order"))
    order = input("How much was the order")
    ordertotal.append(order + shippingCharge)

for i in range(loopController):
    print name[i], ordertotal[i]
Beat_Slayer 17 Posting Pro in Training

Hope it helps.

def voice(x):
    print x

v = threading.Timer(50, voice)
v.start()

Cheers and Happy codings

Beat_Slayer 17 Posting Pro in Training

Create function to voice users and run the function using the timer, instead of passing commands to the timer function.

Beat_Slayer 17 Posting Pro in Training

I don't know if it is this function but this should work.

from scipy.special import kv

Happy coding

Beat_Slayer 17 Posting Pro in Training

It works with your file again. :)

f_in = open('blocks.txt').read()
f_out = open('output.csv', 'w')

f_out.write('AC\tID\tFA\tOS\tSF\tBS\tGE\n')

blocks = [x for x in f_in.split('//') if x]

for item in blocks:
    infos = [x for x in item.split('\n') if x and x != 'XX']
    AC = ''
    ID = ''
    FA = ''
    OS = ''
    SF = ''
    BS = ''
    GE = ''
    for field in infos:
        if field.startswith('AC'):
            AC += ' ' + field[3:]
        elif field.startswith('ID'):
            ID += ' ' + field[3:]
        elif field.startswith('FA'):
            FA += ' ' + field[3:]
        elif field.startswith('OS'):
            OS += ' ' + field[3:]
        elif field.startswith('SF'):
            SF += ' ' + field[3:]
        elif field.startswith('BS'):
            BS += ' ' + field[3:]
        elif field.startswith('GE'):
            GE += ' ' + field[3:]

    f_out.write('%s\t%s\t%s\t%s\t%s\t%s\t%s\n' % (AC, ID, FA, OS, SF, BS, GE))
    
f_out.close()

Cheers and Happy coding

Beat_Slayer 17 Posting Pro in Training

Your welcome.

You can mark as solved,

Cheers and Happy coding