woooee 814 Nearly a Posting Maven

Since each point appears to be a tuple, you can use

print(len(points))
for point in points:
    print(point)
    for each_point in point:
        print("  ", each_point)
        # etc.
woooee 814 Nearly a Posting Maven

You'll have to post the entire error message and state what version of Python you are running for us to help there. However, the statement
while product_price <=0 or product_price=="":
first assumes product_price is an integer, "<=0", and second assumes it is a string,product_price=="". You have to choose one or the other.

woooee 814 Nearly a Posting Maven

Comment the Circle and Box lines and see if you get a line. Then figure out why only Line() works.

from gasp import *
 
begin_graphics()
     
#Circle((200, 200), 60)
Line((100, 400), (580, 200))
#Box((400, 350), 120, 100)
     
update_when('key_pressed')
end_graphics()
woooee 814 Nearly a Posting Maven
woooee 814 Nearly a Posting Maven

For storing a few values, like phone number and e-mail address, you can use a list which is easier to understand and use.

AB={'Joshua' : ['sho0uk0m0o@gmail.com',  '(802) 3-5-2206'],
    'Ashley':  ['a000@gmail.com', '(802) 820-0000']}
print "%s,  e-mail=%s,  phone=%s" % ("Joshua", AB["Joshua"][0], AB["Joshua"][1])

new_name = "Bill"
new_email= "bill@domain.com"
new_phone= "(802) 123-4567"

AB[new_name] = [new_phone, new_email]
print AB
woooee 814 Nearly a Posting Maven

This forum is for Python programs. I would suggest that you ask this question on a ActivePython forum, or an installing Python forum.

woooee 814 Nearly a Posting Maven

And no one came up with a one line solution? We must be loosing our edge.

print [(a, b) for a in [(3015, 3701), (4011, 5890), (10,40), (150,300)] for b in [(3045, 3800), (1,2), (100,200), (4500,6000), (20,145)] if a[1] < b[0]]
woooee 814 Nearly a Posting Maven

There is gap between your specification and my results by purpose as it is DaniWeb policy to help people to learn, which means letting people finish things by (themselves)

+1 So no one is posting complete code, take what has been posted onward.

The way you have described it: for these lists:

lista = [(3015, 3701), (4011, 5890), (10,40), (150,300)]
listb = [(3045, 3800), (1,2), (100,200), (4500,6000), (20,145)]

aend < bstart = 3701 < 4500
                5890 < None
                  40 < 3045, 100, 4500 
                 300 < 3045, 4500

And similarly for the bend < astart test.

This code has not been thoroughly tested.

lista = [(3015, 3701), (4011, 5890), (10,40), (150,300)]
listb = [(3045, 3800), (1,2), (100,200), (4500,6000), (20,145)]
   
def overlap(lista, listb):
    found_a_less = []
    for tup_a in lista:
        holding = [tup_a]
        for tup_b in listb:
            result=check(tup_a, tup_b)
            if result:
                holding.append(tup_b)

        found_a_less.append(holding)
    return found_a_less
     
def check ((astart, aend), (bstart, bend)):
    if aend <= bstart:
        return 1
#    if bend <= astart:
#        found_b.append((bend, astart))
    return 0
     
result=overlap(lista,listb)
for tup in result:
    print tup[0]
    for ctr in range(1, len(tup)):
        print "   ", tup[ctr]
    
result=overlap(listb,lista)
for tup in result:
    print tup[0]
    for ctr in range(1, len(tup)):
        print "   ", tup[ctr]
woooee 814 Nearly a Posting Maven

At some point you will have to use a list to store multiple values. This is something along the lines of what I think you want.

lista = [(3015, 3701), (4011, 5890), (10,40), (150,300)]
listb = [(3045, 3800), (1,2), (100,200), (4500,6000), (20,145)]
     
def overlap(lista, listb):
    a=0
    b=0
    found_list = []
    while a<len(lista) and b<len(listb):
     
        result=check(lista[a],listb[b])
     
        if result <0:
            found_list.append((lista[a], listb[b]))
            a +=1
        elif result > 0:
            found_list.append((lista[a], listb[b]))
            b +=1
        else:     ## no result found in check()
            a += 1

    return found_list
     
def check ((astart, aend), (bstart, bend)):
    if aend <= bstart:
        return -1
    if bend <= astart:
        return 1
    return 0
     
result1=overlap(lista,listb)
for res in result1:
    print res

An alternate solution that compares every tuple in lista to every tuple in listb:

lista = [(3015, 3701), (4011, 5890), (10,40), (150,300)]
listb = [(3045, 3800), (1,2), (100,200), (4500,6000), (20,145)]
     
def overlap(lista, listb):
    found_a_less = []
    found_b_less = []
    for tup_a in lista:
        for tup_b in listb:     
            found_a_less, found_b_less=check(tup_a, tup_b, \
                                       found_a_less, found_b_less)

    return found_a_less, found_b_less
     
def check ((astart, aend), (bstart, bend), found_a, found_b):
    if aend <= bstart:
        found_a.append((aend, bstart))
    if bend <= astart:
        found_b.append((bend, astart))
    return found_a, found_b
     

result_a, result_b=overlap(lista,listb)
for res in result_a:
    print res
print "-"*50
for res in result_b:
    print res
woooee 814 Nearly a Posting Maven

You would first have to encrypt the password, using whatever method your OS uses and then pass the encrypted password (unless it will be encrypted somewhere along the line), as only the very, very foolish store unencrypted passwords.

From the rsync man page
"Some paths on the remote server may require authentication.
If so then you will receive a password prompt when you connect.
You can avoid the password prompt by setting the environment variable
RSYNC_PASSWORD to the password you want to use or using the --password-file option.
This may be useful when scripting rsync."

There is also Grsync, but I have not used it.

woooee 814 Nearly a Posting Maven

I would guess that you should comment line #22 as it is a duplicate of line #1, and so tries to open the same connection. For further help, please post the entire error message, as guessing is not a good thing.

woooee 814 Nearly a Posting Maven

"Scientist's have hypothesized that parasites cause the erratic behavior associated with colony collapse disorder, in which bees abandon the queen. To help bees dodge infection, U.S. Department of Agriculture entomologists are turning to a brewer's specialty: hops, which contain acids that combat parasitic mites."

Discover July/August, 2011

woooee 814 Nearly a Posting Maven

I would suggest something like the following. I am no SQL expert, but using a dictionary to hold the variables eliminates SQL injection problems, or so we think.

cur.execute('SELECT * FROM inventario WHERE codigo==:dic_var', \
                    {"dic_var":resultado})
        recs_list=cur.fetchall()
        #
        #-----take a look at the contents of recs_list FYI
        print recs_list

Also, this code

def OnBuscar(self, event):
    con = lite.connect("MiBase.sqlite")
    cur = con.cursor()

establishes a connection every time the function is called. You should establish a connection once, and store as an instance variable of the class, or pass "cur" to the function (and "con" if using a commit). An example:

class InsertarDato(wx.Frame):
    def __init__(self, parent, id, title):
        self.con = lite.connect("MiBase.sqlite")
        self.cur = self.con.cursor()

    def OnBuscar(self, event):
        resultado = self.tc1.GetValue()
        self.cur.execute('SELECT * FROM inventario WHERE codigo==:dic_var', \
                    {"dic_var":resultado})
        recs_list=self.cur.fetchall()
        print recs_list
Gribouillis commented: nice tip +13
woooee 814 Nearly a Posting Maven

You can multiply the number by 100 and use integers, or truncate to 2 decimal places when printing floats. On most modern computers a float is a binary number as defined by the IEEE Floating Point Arithmetic Standard and represents numbers 1,000,000,000,000 to 0.0000000000000001 (at a minimum). Floats (actually a C double) have plenty of precision for 2 decimal monetary numbers.

x = 0.1+0.2
print repr(x)
y = "%3.2f" % (x)
print y

x = 0.1+0.2+0.005
print repr(x)
y = "%3.2f" % (x)
print y
woooee 814 Nearly a Posting Maven

SQLite is separate from wxPython, so the two are independent of each other. You can enter a value in wxPython, retrieve the value from the wxPython entry box, and then add it to a SQLite database, or vice-versa. I would suggest starting with a simple program that asks for a name, for example, and adds the name to a database. It doesn't matter what it is as long as it is simple . Use one class only for all of the wx statements, and another class for the SQLite statements. Next you can add another function to ask for a name to look up in the database and display the results. You have posted 99 lines of code, and have not stated clearly what the problem is. Start with a smaller program that makes it easy to understand what it does, and state any problems, i.e. what was expected and what actually happened. For example, the wx class would instantiate the SQLite class, which would open the file when the __init__ function is called. You would then retrieve the name or whatever, still in the wx class, and pass it to an "add" function in the SQLite class which would add the record, etc.

woooee 814 Nearly a Posting Maven

Also you should check the value of this statement
out = out + key1[key1.index(i)+3]
to make sure that key1.index(i)+3 isn't greater than the length of the list, key1.

woooee 814 Nearly a Posting Maven

while look () == Void:
will loop indefinitely when they are not equal because the contents of the variable Void and the function look() don't change. You might want to send some variable to look() and return something other than the value of the Void when you want to exit. Functions explained http://greenteapress.com/thinkpython/html/book004.html#toc28

woooee 814 Nearly a Posting Maven

I would suggest printing the first few items in replace. I think you will find that there is more than "tell" in replace, so the line
for tell in replace:
yields an error. You might try inserting this modification:

replace.append(tell)
replace.append(line)
#
# change to
replace.append((tell, line))
#
# and then -----------------------
for tell in replace:
#
# becomes
for item in replace:
    for tell, line in item:
woooee 814 Nearly a Posting Maven

Are there any records in the file? Create a test file so you know what it contains and try it with the program. If the test file works, the problem is the csv file, not the program.

woooee 814 Nearly a Posting Maven

Mechanize is the standard answer to "how do I fill in a form" type questions. I have not used it so can not say what would be required to use it.

woooee 814 Nearly a Posting Maven

You should also be able to use the list as is, something like this:

for i, record in enumerate(reader):
    if (i > 0) and (len(record) > 7): #skip headers & record has all the fields
        print "date =", record[0]
        print "hk   =", record[1]
        print "ba   =", record[2]
        ## etc.
woooee 814 Nearly a Posting Maven

This implies

it only returns the details of the last user in the list

This implies that you only write the last name. You code should be indented as follows, with the write statement under the for() loop.

for name in listofnames:
    account = api.GetUser(name)
    followers = account.followers_count
    csvout.writerow([name, followers])
    print name + ", " + str(followers)

csvfile.close()
woooee 814 Nearly a Posting Maven

"Runs too long" usually means an infinite loop in today's fast CPU world, so if the program is interrupted after a certain period of time, the results may not be correct.

woooee 814 Nearly a Posting Maven

(Reuters) - A mine awareness team in Uganda was horrified to find an unexploded bomb being used as a bell when they visited a school to teach children how to spot bombs, a local newspaper reported.

The Anti-Mine Network organization saw teachers banging the bomb with stones to call children to lessons in a 700-pupil school in a rural area, the Daily Monitor said.

"Its head was still active, which means that if it is hit by a stronger force, it would explode instantly and cause untold destruction in the area," Wilson Bwambale, coordinator of the organization, told the newspaper.

woooee 814 Nearly a Posting Maven

as i said.. not sure what are the big differences between python 2.7 and 3 though.

See "Print Is A Function" here http://docs.python.org/release/3.0.1/whatsnew/3.0.html for the correct way to suppress the newline.

woooee 814 Nearly a Posting Maven

This homework problem comes around every year. horizontal and vertical graphs.

vegaseat commented: thanks for the hint +15
woooee 814 Nearly a Posting Maven

+1 for HTML. People are familiar with web browsers and you can generate the code via Python if you want.

Meaning that if user A asked to perform some task X, which took 10 minutes, user B will not be able to perform a new task Y until X would have ended.

That is usually done via a lock file, which each process checks before it begins.

Gribouillis commented: You taught me something. +13
woooee 814 Nearly a Posting Maven

Multiprocessing has a getPid() function, so you can also use the PID.

woooee 814 Nearly a Posting Maven

A button press is associated with a callback, also called signals and slots, which call a function or class to do the actual work. See how the "self.log" button is connected to the "self.log_timestamp" function in Listing3: logger-qt.py here Another PyQt tutorial for signals and slots.

woooee 814 Nearly a Posting Maven

First, my personal opinion is that "in" is more straight forward than "-1"

#elif self._wordAt[w][-1] != linenum: # occurring on a new line for this word
elif linenum not in self._wordAt[w]
   self._wordAt[w].append(linenum)

To get the number of times it occurs, I would suggest that you print 10 items of the dictionary. This should give you an idea of how to get the number of occurrences for each word; {"the":1, 3, 7} = "the" occurs in 3 lines.

woooee 814 Nearly a Posting Maven

You perhaps want something along the lines of:

class someclass:
    def __init__(self):
        self.somevariable='somevalue'
     
    def somefunction(self):
        print('gotta get here')
     
def someotherfunction(class_instance):
    print "somevariable -->", class_instance.somevariable

    print "somefunction -->", 
    class_instance.somefunction()
     
myclass=someclass()
someotherfunction(myclass)
woooee 814 Nearly a Posting Maven

See "Capturing Output" here http://www.doughellmann.com/PyMOTW/subprocess/index.html#module-subprocess You can do a lot more with subprocess, so continue reading if you want to know more.

woooee 814 Nearly a Posting Maven

Generally, you would store the next time you want to execute, i.e. now+10 seconds,
using a loop,
call the function,
upon the return get the time and calculate the difference between it and the next time and sleep that amount of time,
update the next time, (+10 seconds), and loop again.

Also, Python has a schedule module, as do most operating systems. On Linux you can use cron to execute the program every 10 seconds, if you want to continue forever.

TrustyTony commented: Good advice and not too much. +13
woooee 814 Nearly a Posting Maven

For me by hand and considering rotation and effect through brackets the example should transform like this:

str='A[A[001]BB1A10]11BA10'
-> 'A[A[]BA10]1BA10'
-> 'A[0A[]BA1]1BA10'
-> 'A[A[]BA1]1BA10'
-> 'A[[]BA1]1BA10'
-> 'A[A1[]B]1BA10'
-> 'A[1[]B]1BA10'
-> 'A[1[]B]BA10'

You could further reduce the last line, depending on the bracket rules, as the first "1" is contiguous to "B", ignoring the brackets, so you get
A[[]BA10]BA10
It also depends on when you rotate in the process as
A[001]B
could remain as is if rotated first to A[100]B, or changed completely if the removals are done first. It's all muddy to my feeble brain, so if anyone can post a clear set of rules and their heirarchy it would be helpful.

woooee 814 Nearly a Posting Maven

and if B[A[100]B0] then B[A[100]B] as the 'A' is considered adjacent to the '0'

That doesn't make sense to me at least. How is the final "0" adjacent to "A" even when taking the brackets into consideration.

so how can str='A[A[001]BB1A10]11BA10' become str=A[1A[100]BA]BA10

Where does the first "1" come from in the second string? Just to clear things up, if you have "A[0]" does that convert into just "A" or remain the same because of the brackets. And if the brackets don't matter, with "A[100]" do you test for "A0" before or after the rotation inside the brackets. Finding the previous and next letters, and testing for combinations, is fairly straight forward even when taking the brackets into consideration, but one has to be sure of the rules before that can be done.

woooee 814 Nearly a Posting Maven

Always be busy doing something when your kids are around. And make sure they have some chores to do too. Because one day they might be your care-givers, and you don't want a bunch of lazy people for your care-givers...Red Green

woooee 814 Nearly a Posting Maven

I would not be concerned about the differences between 2.6 and 2.7. Using 2.7 is only slightly different than 2.6. There are some third party packages that are not yet available for 2.7 though.

woooee 814 Nearly a Posting Maven

I think Python gets the locale from your computer, so perhaps that changed with the installation. You can try
locale.setlocale() and see if it helps.

woooee 814 Nearly a Posting Maven

You will have to test the code one piece at a time. The following code is the first part of the code you posted (with the directories that I don't have commented out), and adds some test data to check if the DB connection works. It works on my machine so if it does not work on yours, there may be a permission problem. If it does work, then try adding data for one file only. If that does not work, then you know that it has something to do with the way the file is read and presented to the DB. Since we have no idea what data you are working with we can only go so far.

import os
import sqlite3


#----------------------------------------
# get data from excel file
#----------------------------------------
##os.chdir(u'C://Users//andrew.trench//Desktop//Trust records//Pmb//')
#list_of_files=os.listdir(u'C://Users//andrew.trench//Desktop//Trust records//Pmb')

 # create SQL table and fill it with data
    #----------------------------------------
#os.chdir(u'C://Python26//')
database = sqlite3.connect('trusts.db',timeout=10, isolation_level=None, check_same_thread = False)

cur = database.cursor()
cur.execute('''CREATE TABLE IF NOT EXISTS pretoria (
   RecordNr INTEGER,
   FileNo TEXT,
   TrustName TEXT,
   AuthorizationDate TEXT,
   Auditor TEXT,
   TrusteeSurname TEXT,
   TrusteeFirstName TEXT,
   TrusteeCompany TEXT,
   TrusteeTelephoneWork TEXT)''')

## insert some dummy recs
for ctr in range(10):
    str_ctr = str(ctr)
    test_tuple = (str_ctr, "File"+str_ctr, "Trust"+str_ctr, \
                  "Authoriz"+str_ctr, "Auditor"+str_ctr, "Surname"+str_ctr, \
                  "FirstName"+str_ctr, "Company"+str_ctr, "Tel"+str_ctr)
    cur.execute('INSERT INTO pretoria VALUES (?,?,?,?,?,?,?,?,?)', test_tuple)
database.commit()

##  print all recs to test the add
cur.execute('select * from pretoria')
recs_list = cur.fetchall()
for rec in recs_list:
    print "-"*70
    for each_field in rec:
        print each_field,
    print
woooee 814 Nearly a Posting Maven

Another possible problem:

counter=1
    for rownum in range(sheet.nrows):
        while counter < sheet.nrows:
                counter=counter+1

This code will add (sheet.nrows)*(sheet.nrows-1) records. In other words, it will add each of sheet.nows-1 records, sheet.rows number of times. If you just want to add a record for each sheet.rows, pick one or other, for() or while(). The for() will add one record for each rownum, and the while() will skip the first record and add one record for each counter.

woooee 814 Nearly a Posting Maven

You open the database for every iteration of the for() loop and while() loop but the close is outside of the for() loop. You should open the SQLite database before the
for filename in list_of_files:
Then close it at the same indentation level (no indentation) at the end of the program, since you are inserting into the same DB every time. Also, this while() statement should be an if() since "data" can only have one length

while len(data)>9:
    data.pop((len(data)-1))

and I would print "data" before and after these statements so you know what it contains. If there are any more problems, please include some sample data and the type of object for the variable, "data".

woooee 814 Nearly a Posting Maven

Also, the join() should be outside of the loop. There is no reason to do it every time.

## a dictionary is created with a colon, :, not an equal sign, =
    self.daughters = {1:'node0', 2:'node1'}

def get_as_string(self):
    s = ''
    ## get the keys and convert each key to a string, 
    ## since you want to return one string
    return_list = self.daughters.keys()
    return_list.sort()           ## the keys are now sorted (sort as ints not as strings)
    return_list = [str(x) for x in return_list]     ## convert to a string
    tree_as_string = s.join(return_list)
    return tree_as_string
woooee 814 Nearly a Posting Maven

The Indonesian branch of the Obedient Wives Club, launched early this month in Malaysia, claims to have about 300 members in several cities. Group leader Gina Puspita said the club would offer its members a package of teachings including how to treat their husbands in bed.

woooee 814 Nearly a Posting Maven

The original problem is that the OP is iterating through the list

l=list(s) #['j', 'a', 'n', 'k', 'o', 's', 'i', 'e', 'n', 'a', 'p', 'i', 'v', 'o']
f=[]
for i in l:   ## <-- iterating through the input list
    f.append(l.count(i)) # [1, 2, 2, 1, 2, 1

instead of through a list of letters, which would eliminate the duplicate problem.

l=list(s) #['j', 'a', 'n', 'k', 'o', 's', 'i', 'e', 'n', 'a', 'p', 'i', 'v', 'o']
f=[]
##for i in l:
for i in string.lowercase:   ## "abcdef...etc" --> count each letter once
    f.append(l.count(i)) # [1, 2, 2, 1, 2, 1

but since this is homework, no one wants to give out a complete solution/

woooee 814 Nearly a Posting Maven

Dictionary keys are stored in "hash" order, not the order they were entered (a dictionary is an indexed container, not a sequential one). You should either sort the keys, and then use the sorted list to lookup in the dictionary, or use "ordered dictionary", which usually requires importing "collections" depending on your version of Python.

woooee 814 Nearly a Posting Maven

Is "wx" declared somewhere else in the program, so you have one wx over-riding the other?. You will have to post some code for specific suggestions.

Added import wx.lib statement to the script, but still getting the same error

The same error implies that wx is not installed on that computer.

woooee 814 Nearly a Posting Maven

Why are you going through the following gyrations instead of using "t". Also, please do not use "i", "l", or "O" as variable names as they can look like letters.

t=s.split()
delimiter= ''
s=delimiter.join(t)
l=list(s)
woooee 814 Nearly a Posting Maven

There is not enough info here to really answer your question. The natural response is "don't use big data structures". If you want to choose 100 random records from one million choices then SQL (commit every 1000 records or so when adding is faster than a commit after every record) would probably be faster than a dictionary. Next, you should try one of the profiling packages so you know where the bottlenecks are as it could be creating the dictionary takes the time, as opposed to looking for the 100 random records. PyPy is also something to look into.

i looked over paralelpython.com and i didn't see a mechanism to share big data structures between processes.

Why do you __have__ to share big data structures between processes?

woooee 814 Nearly a Posting Maven

To change the subject a little, we were amazed by how nice a 240x144 dpi "near letter quality" dot matrix printer printed compared to the 60 dpi. But it required two passes at 240x72 each.

woooee 814 Nearly a Posting Maven

The i5 is rated at 2.66GHz (according to HP's website), so a doubling of speed is acceptable compared to a 1.6 GHz machine. The i5 is also a dual processor so you can use parallel python to speed things up. For a simple function, it would be something along these lines:

import pp
ppservers = () 
job_server = pp.Server(ppservers=ppservers)
f1=job_server.submit(process_this, (range(0, 6000)), (), ())
f2=job_server.submit(process_this, (range(6000, 12000)), (), ())