If "n" is not in the range 1-->9 it returns None (when the number entered is 10 for example). If the tens position is a "1" then it is a teens number and you would not print the ones position. Ditto for tens position when it is zero, for the numbers 100, 201 etc.
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
The first iteration of the for loop runs, but nothing else.
That is because of the "if counter > 0"
for counter,row in enumerate(reader):
if counter > 8:
continue
You also have an extra semicolon at the end of this statement
Cur.execute("INSERT INTO vulnerabilities(IP) VALUES ('vuln_0');")
I will try to look at this again tonight and provide a working example, so post back if you get it working before that.
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
You call executemany but only supply one value. What is the point of creating the tuple "tests" or "vuln" instead of supplying the fields directly to the insert statement. You should also open or create the SQLite db once at the top of the function before the for loop. As it is, you open it on every pass through the for loop which will lead to unknown results. Take a look at this tutorial Click Here especially the "INSERT INTO Cars" examples. You have too much code here that is not tested/does not work. Start by testing each piece individually and then go on to the next piece. Post back with the snippet that does not work. Also include some test data and the version of Python, 2 or 3.
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
I would just add both directories to the PYTHONPATH variable in .bashrc. You can also add something like
export PYTHONSTARTUP=$HOME/.pythonstartup
to .bashrc to execute a given file when python starts.
Edit: Sorry, I see now from the "7" and "xp" that you are probably using a windows OS, but am going to leave the reply for any future searchers
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
An infinite loop as play_click is not changed within the while loop
while(self.play_click==0):
self.while_time()
When testing it is a good idea to limit while loops
ctr = 0
while self.play_click==0:
self.while_time()
ctr += 1
if ctr > 99:
print "Counter limit exit from while loop"
self.play_click=99
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
That comes out to June 10th, 14 days off. There would be something like 28 leap years which is too far off to be a possibility. "41401,250002" comes back as May 9th at 6:00 AM (providing January 1, 1900 is correct).
import datetime
x=datetime.datetime(1900, 1, 1, 0, 0, 0) + datetime.timedelta(days=41433.662413)
print x.year, x.month, x.day, x.hour, x.minute, x.second
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
UnicodeDecodeError: 'utf16' codec can't decode byte 0x20 in position 108: truncated data
I assume your are using Python 2.x so try something like this.
book = open_workbook(os.path.join(folder_to_import, file_to_import), coding='utf-16')
If you have unicode file names then use
l_files_to_import = os.listdir(u"/Location/DATA")
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
The old tale is true, you can balance an egg on it's end at the vernal equinox, March 20th this year. You can also balance an egg on it's end any other day of the year.
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
Always use complete names. The program is not looking in the directory that the file is located in. Also, you should be able to use a slash, /directory_name on any OS.
##-------------------------------------------------------------
## Assumes this code is now indented to run under the for() loop
##-------------------------------------------------------------
folder_to_import = '/Location/DATA'
l_files_to_import = os.listdir(folder_to_import)
for file_to_import in l_files_to_import:
if file_to_import.endswith('.XLS'):
column_count=10
# Open entire workbook
book = open_workbook(os.path.join(folder_to_import, file_to_import))
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
A class is a prototype, i.e. it is only a potential object.
class HelloWorld :
def __init__(self):
print("Hi")
def talk(self ,name):
self.nameA = name
print("Hello", self.nameA)
HW1=HelloWorld() ## calls the class or creates an actual instance
HW2=HelloWorld() ## a second, separate instance
HW1.talk("Name 1")
HW2.talk("Name Two")
print HW1.nameA
print HW2.nameA
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
i wanted to use the subprocess module also but i couldn't know how to use it , and got this Error : WindowsError: [Error 2] Le fichier spécifié est introuvable
We don't know what the statment was that produced the error so can not offer any help on how to fix it. Please include the complete error message.
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
The easiest way to eat crow is while it's still warm. The colder it gets, the harder it is to swallow.
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
2nd hit on Google pyusb backend not accessible. You have to install an additional lib that pyusb depends on, and it's also on the pyusb site but the web site isn't real clear saying that you have to install one of the library dependencies. Please mark this as solved.
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
If the car is still in transit, we don't know what the speed is. If there is no traffice, it is faster. If there is a traffic jam it is slow. If the traffice is the same then the speed is the same. If the car has already arrived, it's speed is zero, as it is parked.
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
We don't have the inherited class, EventHandler, and don't know what graphics tool kit you are using, so can not offer any assistance other than to say that you don't call the function "handle" anywhere in the code posted that I can see.
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
If someone enters a wrong user name, or password, or bc, nothing happens. It should be something along the lines of
if Choice==2:
username = ""
while username != uname:
username=raw_input("Login User name: ")
This is definitely a list exercise IMHO and whould be much easier with dictionaries. The point is that you want one container for everything. Then what is printed and what is used when the customer chooses something come from the same place. If you make an error entering somewhere, it may print one price and charge another. Also, when you want to make changes you should be able to change one list/dictionary/file and have it reflect everywhere. This is an example using the first two computers.
## number, price, bar_code, qty_on_hand, description (one line per)
products_list = [
["i5-3570k", 218, '04353736', 5, "Intel Core i5-3570K Quad-Core",
"Socket LGA1155, 3.4Ghz, 6MB L3",
"Cache, 22nm (Retail Boxed) Gen3"],
["i7-3970X", 1009.99, '04322575', 5, "Intel Core i7-3970X Extreme",
"Edition Six Core Socket LGA2011", "3.5 GHz, 15MB L3 Cache"]]
##---------- print all products
## you could use as list of lists as here as well
empty_line = "|" + " "*49 + "|"
dashes = "|" + "-"*49 +"|"
for product in products_list:
## print dashes and product number
output = "|--------------------" + product[0]
output += "-"*(50-len(output)) + "|"
print output
## print price
output = "| Price - " + str(product[1]) + "$"
output += " "*(50-len(output)) + "|"
print output
print empty_line
## print product code
output = "| Product Code - " + product[2]
output += " "*(50-len(output)) + "|"
print output
print empty_line
## print all description lines
output = "| Description - "
start = len(output)-1
description = product[4:]
for each_line in description:
output += each_line
output += " "*(50-len(output)) + "|"
print output
output = "|" + " "*start
print empty_line
print dashes
print
##---------- Now simulate a choice
total_purchase = 0
bc = '04322575'
item_found=False
for item in products_list:
if bc == item[2]:
item_found = True
price=item[1]
name=item[0]
item[3] -= 1 ## reduce inventory
total_purchase += price
if not item_found:
print "item is not on file"
## buy another one
bc = '04322575'
for item in products_list:
if bc == item[2]:
price=item[1]
name=item[0]
item[3] -= 1 ## reduce inventory
total_purchase += price
print "Total purchase price =", total_purchase
print "\nInventory on hand"
for product in products_list:
print "%10s = %d" % (product[0], product[3])
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
Your question was already answered in this post with a demo of converting some words using a dictionary. You insist on using re which produces the undesired results, instead of a dictionary lookup. There is nothing that anyone can do to make bad code work.
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
No "/n". The data is there it's just on one r e a l l y long line.
fp=open("data.txt", "a")
fp.write(dependent_variables)
fp.close()
And it should be
fp=open("data.txt", "a")
## do the input or calcs or whatever
fp.write(dependent_variables)
## do more input and/or calcs
fp.write(dependent_variables)
## at the end of the program
fp.close()
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
You write one ('HBHB', 0xcafe, *ssd) and multiple ('HH', chunk) and then read one ('HBHB', 0xcafe, *ssd) and only one ('HH', chunk), then one ('HBHB', 0xcafe, *ssd) and one ('HH', chunk), etc. In addition to ('HBHB', 0xcafe, *ssd) write the number of items (length) written so you know how many to read.
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9