I thought the same Tony was just starting doing a namedtuple version. Luckly i stoped by to edit my post.
For the csv module I still use because I thought maybe for some csv may have some type of encoding.
I thought the same Tony was just starting doing a namedtuple version. Luckly i stoped by to edit my post.
For the csv module I still use because I thought maybe for some csv may have some type of encoding.
Hope it helps.
import csv
d={}
for row in csv.reader(open('sample.dat')):
d['ID %s' % row[0]] = {'name': row[1], 'email': row[2], 'homeaddress': row[3]}
print d
print
user_id = 125
print 'ID %s:' % user_id, d['ID %s' % user_id]
print
print 'ID %s' % user_id
print 'Name:', d['ID %s' % user_id]['name'],
print 'Email:', d['ID %s' % user_id]['email'],
print 'Home Address:', d['ID %s' % user_id]['homeaddress']
Output:
>>>
{'ID 126': {'homeaddress': ' 459 happy st.', 'name': ' gishi4', 'email': ' gishi4@mymail.com'}, 'ID 124': {'homeaddress': ' 457 happy st.', 'name': ' gishi2', 'email': ' gishi2@mymail.com'}, 'ID 125': {'homeaddress': ' 458 happy st.', 'name': ' gishi3', 'email': ' gishi3@mymail.com'}, 'ID 123': {'homeaddress': ' 456 happy st.', 'name': ' gishi', 'email': ' gishi@mymail.com'}}
ID 125: {'homeaddress': ' 458 happy st.', 'name': ' gishi3', 'email': ' gishi3@mymail.com'}
ID 125
Name: gishi3 Email: gishi3@mymail.com Home Address: 458 happy st.
If the fields are in the same position you can tweak a little the read function and add the fields.
Can you post a sample csv?
Can't you do like this:
d['key']['fieldname']
I was talking about the datetime code Tony.
When I started writing you didn't had edited your post yet.
A simple example. It's only a example, not a finnished code, but you can try to add to the concept of Tony and we'll see where you get. ;)
f_backup = path_to_file
basename, ext = os.splitext(f_backup)
copy_path = path_to_copy
counter =0
while running:
if copied == None and os.path.isfile(f_backup) == 1:
counter += 1
os.copy(f_backup, copy_path + basename + counter + ext)
os.remove(f_backup)
copied = True
if copied == True and os.path.isfile(f_backup) == 1:
os.remove(f_backup)
copied = None
Your code will only run on linux. It looks more like a bash script then a python code.
I just don't get if they are multiple files to copy and if it is to copy every day
or id it only 15 of all the backups that there exist.
If I understood.
extensions = ['.txt', '.jpg', '.zip']
f_name, f_extension = os.path.splitext(filename)
for extension in extensions:
if f_extension == extension:
do_something()
It works perfect here.
VList=[0,0,1,0,1,1,0,0]
if VList.count(1) < 5:
print('Yes')
else:
print('No')
My output:
Yes
One of the problems is here:
b1 = Button(app, text = "Correct!", width = 10, command = play_correct_sound)
b1.pack(side = "left", padx = 10, pady = 10)
b2 = Button(app, text = "Wrong!", width = 10, command = play_correct_sound)
b2.pack(side = "right", padx = 10, pady = 10)
where it shoul be:
b1 = Button(app, text = "Correct!", width = 10, command = play_correct_sound)
b1.pack(side = "left", padx = 10, pady = 10)
b2 = Button(app, text = "Wrong!", width = 10, command = [B]play_wrong_sound[/B])
b2.pack(side = "right", padx = 10, pady = 10)
And maybe switching this:
import pygame.mixer
sounds = pygame.mixer
by this:
from pygame import mixer as sounds
but I don't know much about pygame.
No need to sorry about that.
We all have doubts, and can get confused sometimes.
I was reading that yesterday, thats why it came so fast to me. :)
You can mark as solved.
lol
Happy coding.
I might be wrong, but I believe with may be talking about this.
If it is, you are a litle bit confused, since point is not a data structure, the namedtuple is the data structure you are searching for.
congrats
You need a diferent aproach because the login page it's on php with a javascript login.
Like this:
for row in range(3):
for col in range(4):
print '0',
The intention was to give negative condition on the lines with 'DTP', and not to give positive.
Anyway a litle more refreshed.
f_in = open('input.txt', 'r')
f_out = open('output.txt', 'w')
for line in f_in:
if 'DTP' not in line:
f_out.write(line)
else:
f_out.write(line.replace('DTP', 'NEW_WORD'))
f_in.close()
f_out.close()
Something like:
f_in = open('input.txt', 'r')
f_out = open('output.txt', 'w')
for line in f_in:
if line.find('DTP') == 0:
f_out.write(line)
or
f_in = open('input.txt', 'r')
f_out = open('output.txt', 'w')
for line in f_in:
line.replace('DTP', 'NEW_WORD')
f_out.write(line)
Sorry for the lazyness, but I'm not at home.
The size of the balls should be:
(size of the window - ((number of balls + 1) * spacing)) / number of balls
I'm sorry for the late night cerebral obstipation. :D
I see you were more waken than me, I like your final code, you can delete line 6. It's doing nothing there nomore since the for loop don't use it, and you rewrite it on the begiining of the loop.
Congrats and happy coding.
def unrar():
try:
os.chdir(fileDir)
print "\n-------------"
print "Installing..."
print "-------------\n"
found = None
archive = Unrar2.RarFile(filename)
for file_archive in Unrar2.RarFile(filename).infoiter():
file = os.path.split(file_archive.filename)[-1]
basename, ext = os.path.splitext(file)
if ext == ".package":
print "Found %s. Extracting to \\Packages." % file
archive.extract(file_archive, modDir + "\\Packages", False)
found == True
elif ext == ".dbc":
print "Found %s. Extracting to \\DCCache." % file
archive.extract(file_archive, modDir + "\\DCCache", False)
found == True
if found:
print "\nInstallation successful!"
os.system("pause")
else:
print "No valid files found."
os.system("pause")
os.system("cls")
checkExtension()
Sorry but this is my last try for today, I'm too tired.
Try like this, otherwise tomorrow I'll download the package and try it.
def unrar():
try:
os.chdir(fileDir)
print "\n-------------"
print "Installing..."
print "-------------\n"
found = None
archive = Unrar2.RarFile(filename)
for file_archive in Unrar2.RarFile(filename).infoiter():
file = os.path.split(file_archive.filename)[-1]
basename, ext = os.path.splitext(file)
if ext == ".package":
print "Found %s. Extracting to \\Packages." % file
archive.extract(file, modDir + "\\Packages", False)
found == True
elif ext == ".dbc":
print "Found %s. Extracting to \\DCCache." % file
archive.extract(file, modDir + "\\DCCache", False)
found == True
if found:
print "\nInstallation successful!"
os.system("pause")
else:
print "No valid files found."
os.system("pause")
os.system("cls")
checkExtension()
I'm sorry but I can't test it where I am now, and I'm a litle sleepy. :)
But I think now I got it.
def unrar():
try:
os.chdir(fileDir)
print "\n-------------"
print "Installing..."
print "-------------\n"
found = None
archive = Unrar2.RarFile(filename)
for file_archive in archive.infoiter():
file = os.path.split(file_archive.filename)[-1]
basename, ext = os.path.splitext(file)
if ext == ".package":
print "Found %s. Extracting to \\Packages." % file
archive.extract(file, modDir + "\\Packages", False)
found == True
elif ext == ".dbc":
print "Found %s. Extracting to \\DCCache." % file
archive.extract(file, modDir + "\\DCCache", False)
found == True
if found:
print "\nInstallation successful!"
os.system("pause")
else:
print "No valid files found."
os.system("pause")
os.system("cls")
checkExtension()
Oups... :)
I was sleeping.
def unrar():
try:
os.chdir(fileDir)
print "\n-------------"
print "Installing..."
print "-------------\n"
found = None
for file in Unrar2.RarFile(filename).infoiter():
basename, ext = os.path.splitext(file)
if ext == ".package":
print "Found %s. Extracting to \\Packages." % file
archive.extract(file, modDir + "\\Packages", False)
found == True
elif ext == ".dbc":
print "Found %s. Extracting to \\DCCache." % file
archive.extract(file, modDir + "\\DCCache", False)
found == True
if found:
print "\nInstallation successful!"
os.system("pause")
else:
print "No valid files found."
os.system("pause")
os.system("cls")
checkExtension()
def unrar():
try:
os.chdir(fileDir)
print "\n-------------"
print "Installing..."
print "-------------\n"
found = None
for filename in Unrar2.RarFile(filename).infoiter():
basename, ext = os.path.splitext(filename)
if ext == ".package":
print "Found %s. Extracting to \\Packages." % filename
archive.extract(filename, modDir + "\\Packages", False)
found == True
elif ext == ".dbc":
print "Found %s. Extracting to \\DCCache." % filename
archive.extract(filename, modDir + "\\DCCache", False)
found == True
if found:
print "\nInstallation successful!"
os.system("pause")
else:
print "No valid files found."
os.system("pause")
os.system("cls")
checkExtension()
What's the OS you are coding on?
And how about this.
if name.find(".package") != -1:
print "Found %s. Extracting to \\Packages." % name
archive.extract(name, modDir + "\\Packages", False)
found = True
Edit:
class RarInfo(__builtin__.object)
Represents a file header in an archive. Don't instantiate directly.
Use only to obtain information about file.
YOU CANNOT EXTRACT FILE CONTENTS USING THIS OBJECT.
USE METHODS OF RarFile CLASS INSTEAD.
So....
class RarFile
__del__(self)
__init__(self, archiveName, password=None)
Instantiate the archive.
archiveName is the name of the RAR file.
password is used to decrypt the files in the archive.
Properties:
comment - comment associated with the archive
>>> print RarFile('test.rar').comment
This is a test.
extract(self, condition='*', path='.', withSubpath=True)
Extract specific files from archive to disk.
If "condition" is a list of numbers, then extract files which have those positions in infolist.
If "condition" is a string, then it is treated as a wildcard for names of files to extract.
If "condition" is a function, it is treated as a callback function, which accepts a RarInfo object
and returns either boolean True (extract) or boolean False (skip).
DEPRECATED: If "condition" callback returns string (only supported for Windows) -
that string will be used as a new name to save the file under.
If "condition" is omitted, all files are extracted.
"path" is a directory to extract to
"withSubpath" flag denotes whether files are extracted with their full path in the archive.
Returns list of RarInfos for extracted files. …
I think that at least some code treeish style thingy would give some idea about your achievement.
For some generic information, i believe you have plenty of scripts under the search. :)
Tony I believe they are path directories names, but if it is so they should be doubled.
Something like this:
if name.find(".package") != -1:
print "Found %s. Extracting to \\Packages." % name
archive.extract(name, modDir + "\\Packages")
found = True
I liked it, I've tried some other assembly modules some time ago, and I just found them not so well going.
For the architecture I'm with Tony, about the ARM also, I've been programming for symbian in the last weeks, and I would love it also to have some mobile code sweetness.
Congrats.
I'm not an expert on regex, but you can I think the regex is still right.
Maybe the constituion of the html has changed.
If you replace the read from the url with the html code you gave, it works just fine.
Could it be something related to the talking with the server?
We can test it.
matchstr = urlopen('http://192.168.0.1/stlui/user/allowance_request.html%20target=%22allowance%22').read()
matchstr = '''
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="refresh" Content="60;url=/stlui/user/allowance_request.html">
<title>Download Allowance Status</title></head><body><h3 style="font-size: 150%; color:blue; text-align:center; font-weight:bold">DOWNLOAD ALLOWANCE STATUS</h3><TABLE width='100%' cellpadding='10'><tr><td style="text-align:center;"><h3>Usage within allowance - no download restrictions</h3></td><td><span style="display:block;text-align:center">100%</span><table style="font-size:1; background-color:white; border:1px solid black;" width='15%' cellspacing='0' cellpadding='0' align='center'><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr><tr style="background-color:green"><td> </td></tr></table><span style="display:block;text-align:center">0%</span></td></tr><tr><td> </td><td><table style="font-size:18; border-width:0px;" width=90% cellspacing=0 cellpadding=0 ALIGN=CENTER><tr><td> </td><td style="border-width:0px;">Plan Allowance (MB)</td><td style="border-width:0px;"> 625</td></tr><tr><td> </td><td style="border-width:0px;">Allowance Remaining (MB)</td><td style="border-width:0px;"> 625</td></tr><tr><td><span style="background-color: green;"> </span> </td><td style="border-width:0px;">Allowance Remaining (%)</td><td style="border-width:0px;"> 100</td></tr><tr><td> </td><td style="border-width:0px;">Time Until Allowance Refill</td><td style="border-width:0px;"> 22:18:01</td></tr></table></td></tr></TABLE>
</body>
</html>
'''
I don't get your question and, what you really want to do.
If it is what I think you can just check if the name of the current customer is the name of the winner and display the message.
But fot it to be logic, you ahould be saving all those values in file, and showing the message the next time the customer would log.
f_input = open('input.txt', 'r')
f_output = open('output.txt', 'w')
for currentline in f_input:
newline = currentline.replace(' ', '')
f_output.write(newline)
f_input.close()
f_output.close()
I fixed it for you and made modifications on the list part of the code.
You had also a corrupted file as database, because the format of the lines was not the same you are using now.
I would read the file to a list, find the list item wanted, delete it and write the list to the file.
f = open(addressbook, 'r')
file_records = f.readlines()
f.close()
f = open(addressbook, 'w')
for item in file_records:
if item != '%s %s \n' % (name, phone):
f.write(item)
Something like this maybe.
I think that '*' is wath is causing the warning.
Could we get some code. lol :)
How about leaving the reserved name 'var' and use other name for the variable?
I'm I missing something here?
You need the symbian python modules appuifw and e32 that are in the Python for Symbian SDK.
You can only run them on a emulator on your pc, or on your mobile device.
How about some crossing between the two scripts. ;)
Cumps.
import appuifw
import e32
import inbox
import logs
def Quit():
app_lock.signal()
def message_received(msg_id):
box = inbox.Inbox()
sms_text = box.content(msg_id)
sender = box.address(msg_id)
sender_number = sms_log_in[0]['number']
#To handle received messages.
box = inbox.Inbox()
box.bind(message_received)
#To catch last number by the logs last received message
sms_log_in = logs.sms(mode='in')
#To handle Exit
appuifw.app.exit_key_handler = Quit
app_lock = e32.Ao_lock()
app_lock.wait()
Sure, I'm willing to help mate.
I've got around 70 programs written for symbian in python.
I just love it, because you can write debug and run them on the device, all in a snap. lol :)
You must use the ensymble tool provided with the sdk to make the sis file.
For the icons and the rest of the stuff it's mainly through the use of the appuifw module.
Hi, you don't need all those imports.
You get the correct number that actually sent you the sms with your code.
About mine code, it runs smoothly here.
import appuifw
import e32
import inbox
def Quit():
app_lock.signal()
def message_received(msg_id):
box = inbox.Inbox()
sms_text = box.content(msg_id)
sender = box.address(msg_id)
#To handle received messages.
box = inbox.Inbox()
box.bind(message_received)
#To handle Exit
appuifw.app.exit_key_handler = Quit
app_lock = e32.Ao_lock()
app_lock.wait()
Here it is.
I think it's pretty readable.
I know it is acting weird in the time part becuase of the timezones, but i don't have the time to look at it now. :)
I'll do it later if you can't.
import logs
import time
call_log_in = logs.calls(mode='in')
call_log_out = logs.calls(mode='out')
call_log_fetched = logs.calls(mode='fetched')
call_log_missed = logs.calls(mode='missed')
call_log_in_alt = logs.calls(mode='in_alt')
call_log_out_alt = logs.calls(mode='out_alt')
sms_log_in = logs.sms(mode='in')
sms_log_out = logs.sms(mode='out')
sms_log_fetched = logs.sms(mode='fetched')
sms_log_missed = logs.sms(mode='missed')
sms_log_in_alt = logs.sms(mode='in_alt')
sms_log_out_alt = logs.sms(mode='out_alt')
print "Last 'in' call:"
print call_log_in[0]
print "Last 'in' sms:"
print sms_log_in[0]
last_sms = sms_log_in[0]
print 'The (phone) number associated with the log event: ',
print last_sms['number']
print 'name: ',
print last_sms['name']
print 'A description of the event: ',
print last_sms['description']
print 'The direction associated with the event (i.e. whether incoming or outgoing): ',
print last_sms['direction']
print 'Event status: ',
print last_sms['status']
print 'subject: ',
print last_sms['subject']
print "The event's id: ",
print last_sms['id']
print 'contact: ',
print last_sms['contact']
print 'duration: ',
print last_sms['duration']
print 'duration type: ',
print last_sms['duration type']
print 'flags: ',
print last_sms['flags']
print 'link: ',
print last_sms['link']
print 'The time associated with the event as a unix timestamp: ',
print last_sms['time']
sms_time = time.localtime(last_sms['time'])
utc_time = time.strftime("%Y/%m/%d-%H:%M:%S", sms_time)
print 'UTC time: ',
print utc_time
print 'data: ',
print last_sms['data']
I'll write some hours later, a description script for your question. :)
Can you post some code to make it more clear.
From my experience the sendernumber given by line 18 is the number that sent you the sms. If you reply to that number the sms will go to who sent you.
But if you pick the sendername pick by line 20 then you can have thosekind of problems.
I want to help.
I hope you don't take me wrong. I'm willing to help, I just wanted to see some coding effort also. :)
Here's a test script I've written some time ago. Hope it helps.
And to all the experts, I'm just beginning python and symbian, don't be to arsh on me. :D
import appuifw
import audio
import contacts
import e32
import inbox
import time
appuifw.app.title = u"->>SMSTalk v1"
appuifw.note(u"Loading ->>SMSTalk v1 by Beat_Slayer...", 'info')
print "\nLoading ->>SMSTalk v1 by Beat_Slayer..."
def now():
t = time.time()
hh, mm, ss = time.localtime(t)[3:6]
return (str(hh) + "h:" + str(mm) + "m:" + str(ss)) + "s"
def readsms(index):
sendernumber = inbox.address(index)
sender = list.find(sendernumber)
name = sender[0].title
smstime = inbox.time(index)
content = inbox.content(index)
readit = appuifw.query(u"SMS from " + name + ". Read it?", 'query')
if readit == True:
audio.say(content)
print "\n->>SMSTalk read a message from " + name + " at " + now() + "."
else:
print "\n->>SMSTalk ignored a message from " + name + " at " + now() + "."
def exit_key_handler():
appuifw.note(u"->>SMSTalk v1 successfull!",'conf')
print "\n->>SMSTalk v1 successfull!"
print "Beat_Slayer 2010"
lock.signal()
lock = e32.Ao_lock()
inbox = inbox.Inbox()
list = contacts.open()
print "\n->>SMSTalk v1 waiting for incoming SMS..."
inbox.bind(readsms)
appuifw.app.exit_key_handler = exit_key_handler
lock.wait()
In the documentaion you have all that. Check it.
You can check there and come with some code questions. ;)
I also program on that platform. Cheers! ;)
Again... lol
You can check there and come with some code questions. :)
I also program on that platform. Cheers! :)