[Tutor] Recommendations on Workshops, Courses, Live Online Training

2010-03-11 Thread Khalid Al-Ghamdi
Hi everyone,

I've subscribed to ShowMeDo, but I feel something more than just video
tutorials. Do you have any recommendations on where I can find workshops,
Courses, Live Online Training where I can interact with a real person that I
can ask questions and find the answers I'm looking for. I live in the middle
east, so online live training would be preferable, but I am up for any
ohther recommendation and suggestions.

thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Django Book Recommendation

2010-04-07 Thread Khalid Al-Ghamdi
Hi everyone!

Do you have recommendations regrading good free books or websites to learn
django? I'm a beginner and know the basics of python.

thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] A question about the self and other stuff

2009-10-25 Thread Khalid Al-Ghamdi
Hi everybody,
So I'm new to python and have questions about the following code:

class Robot:
'''Represents a Robot with a name.

Deletes and makes Robots for testing perpuses'''

#a var for counting the number of Robots
population = 0

def __init__(self, name):
'''initializes the data'''
self.name=name
print ('initializing {0}'.format(self.name))

Robot.population+=1

def __del__(self):
'''I'm dying'''
print ('{0} is being destroyed!'.format(self.name))

Robot.population-=1

if Robot.population==0:
print ("{0} was the last one".format(self.name))
else:
print ("there are still {0:d} Robots
working".format(Robot.population))


def Sayhi (self):
'''This is just a hi thing.

Just to say hi<<< to practice convention of docstrings'''

print ('hello, khalid calls me {0}'.format(self.name))

def howMany():
'''prints how many'''

print ('we have {0:d} Robots'.format (Robot.population))

howMany= staticmethod(howMany)

droid1 = Robot('D23')
droid1.Sayhi()
Robot.howMany()

droid2 = Robot('F0009')
droid2.Sayhi()
Robot.howMany()

print ("\nRobots can do some work here\n")
print ("Robots have finished their work. So let's destroy them")

del droid1
del droid2
Robot.howMany()


1- In the class definition above, I don't get the "self.name=name". I
understand that the self is supposed to refer to the actual object, but
since it is an initialization method, there is no way to enter a name in
place of the arguments.
2- in the final few lines where I assign an object to the class, I notice
that a parameter was entered in the class name, "Robot(D23)", although when
defining the class I didn't put any arguments for it.
3- what is the difference between all the underscore, underscore attributes
like:__class__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__',
'__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__',
'__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__setattr__

and the rest of the normal methods for a class.?

I know, lots of questions, but what can i say... I am new!!

so can you guy/gals help?

thanks a million.

khalid
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] os.environ question

2009-11-11 Thread Khalid Al-Ghamdi
hi,

can anyone tell me why on python 2.6 i can enter *os.environ* and then get
all the items that that pertain to the os while on python 3 you just get the
following:



with no items?

thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] getting python 3 to run from the command line

2009-11-14 Thread Khalid Al-Ghamdi
Hi,

for some reason I haven't been able to get python 3 to work from the the
command line. I've added it to the the path in the the system variables but
still no luck. when I try to run python 2.6 it works flawlessly, though,
bearing in mind that it wasn't added to the system variables!

i'm running windows vista and have python 30 ,31 and 26 installed.

all of this , by the way, was just to get easy install to work so i can get
nose working to do some practice of unit testing!

can anyone shed some light on the issue?

thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] getting python 3 to run from the command line (version 2)

2009-11-14 Thread Khalid Al-Ghamdi
hi all,

I realize my question was previous question was phrased, well, vaguely, as I
learn from your responses so here's version 2 of my question:

i'm running windows vista and have python 30 ,31 and 26 installed.!

when I try to run python form the command line by printing *python *to
whichever path i have there (in my case:C:\users\KE>) it runs python 30, but
when i try to code something it just gives me a new line without any
processing of the code. (for example:2+2 returns a new line)

when I tried to change the path to the directory that contains python 31 and
enter *python (c:\python31>)*,  it just crashes and gives me the following
message:


*fatal python error: Py_Initialize: can't initialize sys standard streams
> *

*LookupError: unknown encoding: cp720*
*
*
*This application has requested the Runtime to terminate it in an unusual
way. *
*Please contact teh application's support team for more Information.*
*
*
When i change the directory to c:\python26 and then enter it works ok.

so can anyone tell me why this is happening?

PS: I learn from Alan Gauld's response that windows defaults to python30
when i enter python because in the system variables python30 was entered
first and I confirmed that that was true, but still python 30 doesn't
process my code and python 31 crashes.

thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] [Errno 9] Bad file descriptor

2009-11-30 Thread Khalid Al-Ghamdi
Hi everybody,

I'm running python 2.6.1 on vista and I'm trying to use the csv module to
write to a csv file and get the average of some numbers, but I keep getting
the following error:

Traceback (most recent call last):
  File "C:\Python31\MyCSVProjectFinal.py", line 83, in 
writer.writerow(headings)
IOError: [Errno 9] Bad file descriptor

line 83 refers to the following code, specifically to the one in capital (in
the actual code it's not in capital by the way):

headings = linesInCSV[0] # e.g. ['Measured1', 'Measured2']
csvOutFileName = easygui.filesavebox(title = "Choose output file for
averages", )
if csvOutFileName is not None:
print "Saving using: "+csvOutFileName
csvOut = file(csvOutFileName, 'rb')
writer = csv.writer(csvOut)
*WRITER.WRITEROW(HEADINGS)*
for index in range(len(measured1)):
writer.writerow([measured1[index], measured2[index]])
writer.writerow([averaged1, averaged2])
else:
print "No filename for saving"


so, my problem is I don't know why it keeps giving me this error. I've
checked on the internet, but I haven't found anything to help resolve this
error.

I hope you can be of help.

PS: I've added the complete code below for reference.

thanks


import csv
import sys
import easygui

def getFileAndPath():
"Get fully-qualified path to the csv file"
# TODO argInitialFile = '*.csv'
fileAndPath = easygui.fileopenbox(title="Select .CSV file")
print "Using:",fileAndPath
return fileAndPath

def getLinesInCSVFile(fileAndPath):
"read lines in CSV file, return a list of these lines"
linesInCSV = []
reader = csv.reader(open(fileAndPath, "rb"))
for row in reader:
linesInCSV.append(row)
return linesInCSV

def justNumbers(listOfStrings):
"True if the list contains just numbers represented as strings"
# e.g. ['22.4', '23.9']
isJustNumbers = True
for item in listOfStrings:
try:
nbr = float(item)
except ValueError:
isJustNumbers = False
return isJustNumbers

def getNumbers(listOfStrings):
"Convert a list of strings-of-numbers to a list of numbers, e.g.
['22.4', '23.9'] -> [22.4, 23.9]"
numbers = []
for item in listOfStrings:
nbr = float(item)
numbers.append(nbr)
return numbers

def average(values):
"""Computes the arithmetic mean of a list of numbers"""
return sum(values, 0.0) / len(values)

if __name__ == "__main__":
# get the file-name
#fileAndPath = getFileAndPath()
# NOTE quick hack to make our test/development process quicker
fileAndPath = "c:\\testing\\measured2.csv"

# read the CSV file
linesInCSV = getLinesInCSVFile(fileAndPath)

measured1 = []
measured2 = []
for n in range(1,4):
line = linesInCSV[n]
isJustNumbers = justNumbers(line)
if not isJustNumbers:
print "ERROR!  Expected a line of numbers, instead we got:",line
sys.exit()
# we only get here if justNumbers reports that we only have numbers

# so we can extract the list of floating-point numbers
numbers = getNumbers(line)
measured1.append(numbers[0])
measured2.append(numbers[1])
averaged1 = average(measured1)
averaged2 = average(measured2)

# Show values of Measured1 in a choicebox
# We don't care about the choices, this is just for output
#easygui.choicebox(message = "Sorted values in Measured1", title =
"Measured1", choices = measured1)

headings = linesInCSV[0] # e.g. ['Measured1', 'Measured2']
csvOutFileName = easygui.filesavebox(title = "Choose output file for
averages", )
if csvOutFileName is not None:
print "Saving using: "+csvOutFileName
csvOut = file(csvOutFileName, 'rb')
writer = csv.writer(csvOut)
writer.writerow(headings)
for index in range(len(measured1)):
writer.writerow([measured1[index], measured2[index]])
writer.writerow([averaged1, averaged2])
else:
print "No filename for saving"
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Dictionary Comprehensions

2009-12-04 Thread Khalid Al-Ghamdi
Hi everyone!

I'm using python 3.1 and I want to to know why is it when I enter the
following in a dictionary comprehension:

>>> dc={y:x for y in list("khalid") for x in range(6)}

I get the following:
{'a': 5, 'd': 5, 'i': 5, 'h': 5, 'k': 5, 'l': 5}

instead of the expected:
{'a': 0, 'd': 1, 'i': 2, 'h': 3, 'k': 4, 'l': 5}

and is there a way to get the target (expected) dictionary using a
dictionary comprehension.

note that I tried sorted(range(6)) also but to no avail.

thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] What books do you recommend?

2009-12-08 Thread Khalid Al-Ghamdi
Hi,

I wan't to buy some books about python 3. Do you have any recommendations?

I started with no previous programming experience, and I've finished a few
tutorials  and I guess I can be considered a beginner.

My problem, though, is I still find it difficult to write meaningful code or
use the built in libraries effectively and/or correctly because I can't find
example code to mimic. I tried sifting through ActiveState recipes page, but
most of the code seems uninteresting or useful only if utilized in a bigger
project.

I hope you have some suggestions.

Thanks a lot.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] tkinter issue in python 3

2011-08-07 Thread Khalid Al-Ghamdi
Hi all,

I'm studying this
tutorialabout
tkinter, but it that it's code in a 2.X.

I'm using the following code in python 3, but when i hit quite in the
resulting widget it hangs. I've tried modifying the things I know about to
no avail. Can anyone help?

Here's my code:

from tkinter import *

class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()

self.button=Button(frame, text='Quit', fg='red', command=frame.quit)
self.button.pack(side=LEFT)

self.hi_there=Button(frame, text='hello', command=self.say_hi)
self.hi_there.pack(side=LEFT)

def say_hi(self):
print('hi there, everyone')

root=Tk()
app = App(root)
root.mainloop()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Tutorials on csv module??

2011-08-24 Thread Khalid Al-Ghamdi
Hi everyone,

can anyone point me to a good tutorial on using the csv module?

also, is there a module that can help me check data in a excel file other
than the csv module?

thanks a lot

khaild
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] why is this so?

2011-09-18 Thread Khalid Al-Ghamdi
Hi All,

why is this so?

>>> type('love')

>>> "love" is str
False
>>>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Library of Module for Analyzing Answer Cards

2012-03-22 Thread Khalid Al-Ghamdi
Hi All,

I work in in academic testing environment and we employ expensive machines
to scan answer sheets (the ones where you blacken the letter of the correct
multiple choice answer). Anyway, I was thinking if there was a way we could
use regular old scanners to scan the sheets than analyze the images to
score the tests.

Do you know any modules or libraries in python that can be helpful in that?
Also, what approach if any would you employ to tackle this project?

thanks a million,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Question about login=''.join(choice(lc) for j in range(llen))

2012-04-03 Thread Khalid Al-Ghamdi
Hi,

The following code tries to generate some dummy data for regex exercises.
My question is in reference the line before last:

dom="".join(choice(lc) for j in range (dlen))

how does the interpreter know what "j" is supposed to refer to when it was
not mentioned prior?


from random import randrange, choice
from string import ascii_lowercase as lc
from sys import maxsize
from time import ctime

tlds = ('com', 'edu', 'net', 'org', 'gov')

for i in range(randrange(5,11)):
dtint=randrange(maxsize)#pick a random number to use to generate
random date in next line
dtstr=ctime(dtint)  #date string
llen=randrange(4,8) #login is shorter
login=''.join(choice(lc) for j in range(llen))
dlen=randrange(llen,13) #domain is longer
dom="".join(choice(lc) for j in range (dlen))

print('{}::{}@{}.{}::{}-{}-{}'.format(dtstr,login,dom,choice(tlds),dtint,llen,dlen))
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] regex question

2012-04-05 Thread Khalid Al-Ghamdi
hi all,

I'm trying to extract the domain in the following string. Why doesn't my
pattern (patt) work:

>>> redata
'Tue Jan 14 00:43:21 2020::eax...@gstwyysnbd.gov::1578951801-6-10 Sat Jul
31 15:17:39 1993::rz...@wgxvhx.com::744121059-5-6 Mon Sep 21 20:22:37
1987::ttw...@rpybrct.edu::559243357-6-7 Fri Aug  2 07:15:23
1991::t...@mgfyitsks.net::681106523-4-9 Mon Mar 18 19:59:47
2024::dgz...@fhyykji.org::1710781187-6-7 '
>>> patt=r'\w+\.\w{3}(?<=@)'
>>> re.findall(patt,redata)
[]

This pattern works but the first should, too. shouldn't it?

>>> patt=r'\w+\.\w{3}'
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Is socket.socket() a func or a class

2012-04-05 Thread Khalid Al-Ghamdi
hi all,

I'm reading this book that says when creating a socket you have to use the
socket.socket() *function *as in :

ss=socket.socket()

but whey i check they type it says it's a class which makes sense cause
you're creating a socket object.

>>> type(ss)


so, which is it? or do authors loosely use these terms interchangeably in
this context?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] a problem with a server and client

2012-04-06 Thread Khalid Al-Ghamdi
hi,

i'm trying to implement a server that adds a time stamp to incoming text
form a client.

the server's code is (but doesn't seem to have the problem as demoed by the
error below:

from socket import *
from time import ctime

HOST = ''
PORT = 21567
BUFSIZ = 1024
ADDR =(HOST, PORT)

tcpSerSock = socket(AF_INET, SOCK_STREAM)

tcpSerSock.bind(ADDR)
tcpSerSock.listen(5)

while True:
print('waiting for connection ...')
tcpCliSock, addr =tcpSerSock.accept()
print('...connected from: ', addr)

while True:
data = tcpCliSock.recv(BUFSIZ)
if not data:
break
tcpCliSock.send('[{}] {}'.format(bytes(ctime(), 'utf-8'),data))

tcpCliSock.close()
tcpSerSock.close()



the client's code is:

from socket import *


HOST = 'localhost'
PORT = 21567
BUFSIZ = 1024
ADDR =(HOST, PORT)

tcpCliSock = socket(AF_INET, SOCK_STREAM)

tcpCliSock.bind(ADDR)

while True:
data=input('> ')
if not data:
break
tcpCliSock.send(data)
data = tcpCliSock.recv(BUFSIZ)
if not data:
break
print(data.decode('utf-8'))

tcpCliSock.close()

the problem is i get the following error when i enter some text:

Traceback (most recent call last):
  File "C:\Python32\tsTclnt3.py", line 17, in 
tcpCliSock.send(data)
TypeError: 'str' does not support the buffer interface

can you help?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] a problem with a server and client

2012-04-06 Thread Khalid Al-Ghamdi
yah i did the search, and tried the solution, but it didn't work nice
of you to have tried, though...

anyhow, i found where the problem is... on the client side it should be
connect() instead of bind() in :

> tcpCliSock.bind(ADDR)

thanks

On Fri, Apr 6, 2012 at 4:59 PM, Evert Rol  wrote:

> > i'm trying to implement a server that adds a time stamp to incoming text
> form a client.
> >
> > the server's code is (but doesn't seem to have the problem as demoed by
> the error below:
> >
> > from socket import *
> > from time import ctime
> >
> > HOST = ''
> > PORT = 21567
> > BUFSIZ = 1024
> > ADDR =(HOST, PORT)
> >
> > tcpSerSock = socket(AF_INET, SOCK_STREAM)
> >
> > tcpSerSock.bind(ADDR)
> > tcpSerSock.listen(5)
> >
> > while True:
> > print('waiting for connection ...')
> > tcpCliSock, addr =tcpSerSock.accept()
> > print('...connected from: ', addr)
> >
> > while True:
> > data = tcpCliSock.recv(BUFSIZ)
> > if not data:
> > break
> > tcpCliSock.send('[{}] {}'.format(bytes(ctime(), 'utf-8'),data))
> >
> > tcpCliSock.close()
> > tcpSerSock.close()
> >
> >
> >
> > the client's code is:
> >
> > from socket import *
> >
> >
> > HOST = 'localhost'
> > PORT = 21567
> > BUFSIZ = 1024
> > ADDR =(HOST, PORT)
> >
> > tcpCliSock = socket(AF_INET, SOCK_STREAM)
> >
> > tcpCliSock.bind(ADDR)
> >
> > while True:
> > data=input('> ')
> > if not data:
> > break
> > tcpCliSock.send(data)
> > data = tcpCliSock.recv(BUFSIZ)
> > if not data:
> > break
> > print(data.decode('utf-8'))
> >
> > tcpCliSock.close()
> >
> > the problem is i get the following error when i enter some text:
> >
> > Traceback (most recent call last):
> >   File "C:\Python32\tsTclnt3.py", line 17, in 
> > tcpCliSock.send(data)
> > TypeError: 'str' does not support the buffer interface
>
> Did you try to search on the error string? That would have gotten you the
> solution (even) faster.
> The first two Google hits (and probably all the rest of them), tell me
> that Python 3's socket.send() method wants bytes as input, not str. See
> http://docs.python.org/py3k/library/socket.html#socket.socket.send
>
> Hope that helps,
>
>  Evert
>
>
> >
> > can you help?
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] a problem with a server and client

2012-04-06 Thread Khalid Al-Ghamdi
actually, you are right... in addition to that problem, there was the
encodeing/decoding issue you mentioned on both the client and server.

thanks

On Fri, Apr 6, 2012 at 5:08 PM, Khalid Al-Ghamdi wrote:

> yah i did the search, and tried the solution, but it didn't work nice
> of you to have tried, though...
>
> anyhow, i found where the problem is... on the client side it should be
> connect() instead of bind() in :
>
> > tcpCliSock.bind(ADDR)
>
> thanks
>
>
> On Fri, Apr 6, 2012 at 4:59 PM, Evert Rol  wrote:
>
>> > i'm trying to implement a server that adds a time stamp to incoming
>> text form a client.
>> >
>> > the server's code is (but doesn't seem to have the problem as demoed by
>> the error below:
>> >
>> > from socket import *
>> > from time import ctime
>> >
>> > HOST = ''
>> > PORT = 21567
>> > BUFSIZ = 1024
>> > ADDR =(HOST, PORT)
>> >
>> > tcpSerSock = socket(AF_INET, SOCK_STREAM)
>> >
>> > tcpSerSock.bind(ADDR)
>> > tcpSerSock.listen(5)
>> >
>> > while True:
>> > print('waiting for connection ...')
>> > tcpCliSock, addr =tcpSerSock.accept()
>> > print('...connected from: ', addr)
>> >
>> > while True:
>> > data = tcpCliSock.recv(BUFSIZ)
>> > if not data:
>> > break
>> > tcpCliSock.send('[{}] {}'.format(bytes(ctime(), 'utf-8'),data))
>> >
>> > tcpCliSock.close()
>> > tcpSerSock.close()
>> >
>> >
>> >
>> > the client's code is:
>> >
>> > from socket import *
>> >
>> >
>> > HOST = 'localhost'
>> > PORT = 21567
>> > BUFSIZ = 1024
>> > ADDR =(HOST, PORT)
>> >
>> > tcpCliSock = socket(AF_INET, SOCK_STREAM)
>> >
>> > tcpCliSock.bind(ADDR)
>> >
>> > while True:
>> > data=input('> ')
>> > if not data:
>> > break
>> > tcpCliSock.send(data)
>> > data = tcpCliSock.recv(BUFSIZ)
>> > if not data:
>> > break
>> > print(data.decode('utf-8'))
>> >
>> > tcpCliSock.close()
>> >
>> > the problem is i get the following error when i enter some text:
>> >
>> > Traceback (most recent call last):
>> >   File "C:\Python32\tsTclnt3.py", line 17, in 
>> > tcpCliSock.send(data)
>> > TypeError: 'str' does not support the buffer interface
>>
>> Did you try to search on the error string? That would have gotten you the
>> solution (even) faster.
>> The first two Google hits (and probably all the rest of them), tell me
>> that Python 3's socket.send() method wants bytes as input, not str. See
>> http://docs.python.org/py3k/library/socket.html#socket.socket.send
>>
>> Hope that helps,
>>
>>  Evert
>>
>>
>> >
>> > can you help?
>> > ___
>> > Tutor maillist  -  Tutor@python.org
>> > To unsubscribe or change subscription options:
>> > http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] need help with a script..

2012-04-11 Thread Khalid Al-Ghamdi
Hi All,

I'm using python 3.2 on a windows xp.

I wrote the below script and ran it with the hope of returning a list of
proctors (list_proc), but when it runs it  doesn't call the function
convert_proctors() as intended. On the other hand, when i import the module
from the IDLE prompt and call the convert_proctors() function, the function
returns the desired list.

Why is this so?

Thanks


   1. import csv
   2.
   3. proctor_file=r'c:\Python32\Khalid Stuff\Testing_Scheduler\p
   roctors.csv'
   4.
   5.
   6. def convert_proctors():
   7. proctor_csv_reader = csv.reader(open(proctor_file))
   8. proctor_list=list(proctor_csv_reader)
   9. list_proc=[]
   10. for row in range(len(proctor_list)):
   11. list_proc.append(proctor_list[row][0])
   12. return (list_proc)
   13.
   14.
   15. convert_proctors()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help with a script..

2012-04-11 Thread Khalid Al-Ghamdi
got it thanks a lot

On Wed, Apr 11, 2012 at 4:59 PM, Jerry Hill  wrote:

> On Wed, Apr 11, 2012 at 9:50 AM, Khalid Al-Ghamdi 
> wrote:
> > Hi All,
> >
> > I'm using python 3.2 on a windows xp.
> >
> > I wrote the below script and ran it with the hope of returning a list of
> > proctors (list_proc), but when it runs it  doesn't call the function
> > convert_proctors() as intended. On the other hand, when i import the
> module
> > from the IDLE prompt and call the convert_proctors() function, the
> function
> > returns the desired list.
> >
> > Why is this so?
>
> When you run that code as a script, it does call your
> convert_proctors() function.  But since all you do is create a list,
> and you never save it to disk, or print it to the screen, or even
> assign it to a variable, the result is just thrown away.  Try changing
> the last line to:
>
> print(convert_proctors())
>
> and you'll see the results you were expecting.
>
> --
> Jerry
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Questions Regarding Sockets

2012-04-14 Thread Khalid Al-Ghamdi
Hi All,

(python 3.2 on windows)

I have a couple of questions regarding the below code:

1- In line (15), what are these variables tcpCliSock, addr supposed to hold
and do?
2- Why do I have to specify the buffer size and what does it mean?
3- When I try to run the below code and its corresponding client it works
ok for the first time, but then it gives me this error:

Traceback (most recent call last):
  File "C:\Python32\Khalid Stuff\tsTserv3.py", line 12, in 
tcpSerSock.bind(ADDR)
socket.error: [Errno 10048] Only one usage of each socket address
(protocol/network address/port) is normally permitted

I thought it had to do with  the address so I changed the port and it
worked ok. so,:

A/ isn't the optional tcpSerSock.close() supposed to close the connection
for later reuse?
B/ why is it when i go to the IDLE and enter tcpSerSock.close() and it
accepts it, it still gives the same error and doesn't close the connection
for reuse by my code?

Thanks a lot


   1. from socket import *
   2. from time import ctime
   3.
   4. HOST = ''
   5.  PORT = 21567
   6.  BUFSIZ = 1024
   7.  ADDR =(HOST, PORT)
   8.
   9. tcpSerSock = socket(AF_INET, SOCK_STREAM)
   10. tcpSerSock.bind(ADDR)
   11.  tcpSerSock.listen(5)
   12.
   13. while True:
   14.  print('waiting for connection ...')
   15. tcpCliSock, addr = tcpSerSock.accept()
   16. print('...connected from: ', addr)
   17.
   18. while True:
   19.  data = tcpCliSock.recv(BUFSIZ)
   20.  if not data:
   21.  break
   22. tcpCliSock.send(bytes('[{}] {}'.format(ctime(),data.decode(
   'utf-8')),'utf-8'))
   23.
   24. tcpCliSock.close()
   25.  tcpSerSock.close()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Questions Regarding Sockets

2012-04-15 Thread Khalid Al-Ghamdi
Thanks a lot. You've been, as usual, very helpful.

On Sat, Apr 14, 2012 at 8:32 PM, Alan Gauld wrote:

> On 14/04/12 17:41, Khalid Al-Ghamdi wrote:
>
>  1- In line (15), what are these variables tcpCliSock,addr supposed to
>> hold and do?
>>
>
> The socket object and the IP address of the client that is connecting to
> the server. When a client connects to a server the server assigns a new
> temporary socket connection that the client  uses. Each connection gets a
> new temporary socket assignment. What happens to the old one is
> implementation dependent and you should not try to reuse it.
>
>
>  2- Why do I have to specify the buffer size and what does it mean?
>>
>
> A buffer is an area of memory used as a kind of holding bay into which
> data is put, usually temporarily. You need to specify where the incoming
> data will go and how much space you expect to use.
>
>
>  3- When I try to run the below code and its corresponding client it
>> works ok for the first time, but then it gives me this error:
>>
>> Traceback (most recent call last):
>>   File "C:\Python32\Khalid Stuff\tsTserv3.py", line 12, in 
>> tcpSerSock.bind(ADDR)
>> socket.error: [Errno 10048] Only one usage of each socket address
>> (protocol/network address/port) is normally permitted
>>
>> I thought it had to do with  the address so I changed the port and it
>> worked ok. so,:
>>
>> A/ isn't the optional tcpSerSock.close() supposed to close the
>> connection for later reuse?
>>
>
> Yes, but there is sometimes a delay before the OS cleans up, it may be
> that which you are seeing.
>
>
>  B/ why is it when i go to the IDLE and enter tcpSerSock.close() and it
>> accepts it, it still gives the same error and doesn't close the
>> connection for reuse by my code?
>>
>
> It may be an OS level thing. But I'm by no means an expert on the OS
> networking layers! Which OS are you running under?
>
>
>   HOST = ''
>>  PORT = 21567
>>  BUFSIZ = 1024
>>  ADDR =(HOST, PORT)
>>  tcpSerSock = socket(AF_INET, SOCK_STREAM)
>>  tcpSerSock.bind(ADDR)
>>  tcpSerSock.listen(5)
>>
>>  while True:
>>   print('waiting for connection ...')
>>   tcpCliSock, addr = tcpSerSock.accept()
>>   print('...connected from: ', addr)
>>   while True:
>>   data = tcpCliSock.recv(BUFSIZ)
>>   if not data:
>>break
>>   tcpCliSock.send(bytes('[{}]
>>   {}'.format(ctime(),data.**
>> decode('utf-8')),'utf-8'))
>>   tcpCliSock.close()
>>  tcpSerSock.close()
>>
>
> I can't help but think you should check if there actually is a connection
> before starting the second loop... What do you expect
> if the accept() fails to find anything?
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] tkinter question

2012-04-26 Thread Khalid Al-Ghamdi
hi everyone,

I'm usting python 3.2 on windows, and I'm doing these GUI exercises using
tkinter.

I've created this simple window with two widgets (a label and a button) the
button is supposed to  exit the root window, but the problem is it doesn't
seem to, for some reason. It looks like it is "trying to", but the window
persists for some reason and becomes unresponsive. I'm NOT doing this in
IDLE as i know there are issues with this. so is it an issue the Windows?
or What?


   1. import tkinter
   2. top=tkinter.Tk()
   3.
   4. salam = tkinter.Label(top,text='salam')
   5. salam.pack()
   6.
   7. quit= tkinter.Button(top, text='quit', command=top.quit,bg='red',fg=
   'white')
   8. *
   *
   9. quit.pack(fill=tkinter.X)
   10.
   11. tkinter.mainloop()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] advice on an app

2012-05-01 Thread Khalid Al-Ghamdi
hi all,

I'm trying to create an app that schedules 3000 to 5000 trainees'
practical exams.

All the trainees basic info (name, badge, major, etc.) is in excel and i've
managed to convert it into a *HUGE *list via a csv.reader object.

My question is: is this the right way to go or should i use sqlight3
instead?

thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sqlite3 question

2012-05-23 Thread Khalid Al-Ghamdi
hi all,

I'm using Python 3 and have read that you need sqlite to be installed to
use the sqlite3 module, but when it is imported it seems to work ok. so, do
you need to install it? also, when you create the database where is it
saved?


thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sqlite3 Question

2012-06-06 Thread Khalid Al-Ghamdi
Hi All,

hi Joel,

Regarding sqlite3 practice code below:


   1. import sqlite3
   2. conn=sqlite3.connect("mydb2.db")
   3. c=conn.cursor()
   4. c.execute('create table family (Id integer primary key, name text,
   age integer)')
   5. c.execute("insert into family values (1,'elham',32)")
   6. c.execute('select * from family')
   7. conn.commit()
   8. for i in c:
   9. print(i)


Why is it that if I call the for statement in the shell it doesn't print
the information more than once? I've found this to be true in other
situations where cursor carries the data only once. So, how can i
manipulate/use the data if I can only access it once? I have tried applying
useing x=list(c), but it doesn't seem to work!

Any guidance?

Thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sqlite3 Dilemma

2012-07-30 Thread Khalid Al-Ghamdi
Hi All,

I am a teacher at an industrial training center. We have to conduct
hands-on exams (fixing pumps, etc). I review all the test schedules for all
the students (made by other teachers) to make sure there are no clashes due
to lack of ample supply of equipment or tools. Meaning no two trainees are
to have the same test at the same time. If this is the case, then the date
or time or test code have to be changed to avoid the conflict.

I have the schedule in csv format. I have been able to export it to sqlite3
as seen below and I have found all the conflicts, too.

My dilemma is how to go about making sqlite3 alter the date, time, or exam
code if another trainee is scheduled at the same time and date with the
same test code.

What is the proper approach to handle this?

I'm using python 3 on windows.

Below is how far I've gotten.

Thanks


   1. import csv, sqlite3
   2.
   3.
   4. conn = sqlite3.connect(":memory:") #unless this is ":memory:" this
   database will be created in your CWD which is the resolver folder
   5. c = conn.cursor()
   6. c.execute("create table test (teams integer, sn integer, badge
   integer ,name text, grp integer,\
   7. major text, track text, stage text,  tc text, subject, text, course
   text, ws text, date text, \
   8. time text, proctor text, code text, no integer)")
   9.
   10. reader = csv.reader(open("final.csv", "r"))
   11.
   12. for (teams, sn, badge , name, grp, major, track, stage, tc, subject,
course, ws,\
   13. date, time, proctor, code, no) in reader:
   14. c.execute('INSERT INTO test \
   15.(teams, sn, badge, name, grp, major, track, stage,tc, subject,
   course, ws, date, time, proctor, code, no)\
   16.VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
   17. (teams, sn, badge, name, grp, major, track, stage, tc,subject,
course, ws, date, time, proctor,code, no))
   18.
   19. c.execute("select code, date, time, count (*) from test group by
   code, date, time having count(*)>1")
   20. c1_list=list(c.fetchall())
   21. print(c1_list)
   22. print("your table has {} clashes".format(len(c1_list)))
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sqlite3 Dilemma

2012-07-30 Thread Khalid Al-Ghamdi
Thanks for your input Walter. Are there any techniques to achieve this via
code or sql you share. Because I was thinking along the same you mentioned
but didnt knwo how to go about it.

بتاريخ الاثنين، ٣٠ يوليو، ٢٠١٢، جاء من Walter Prins wpr...@gmail.com:

> On 30 July 2012 14:57, Khalid Al-Ghamdi >
> wrote:
> > Hi All,
> >
> > I am a teacher at an industrial training center. We have to conduct
> hands-on
> > exams (fixing pumps, etc). I review all the test schedules for all the
> > students (made by other teachers) to make sure there are no clashes due
> to
> > lack of ample supply of equipment or tools. Meaning no two trainees are
> to
> > have the same test at the same time. If this is the case, then the date
> or
> > time or test code have to be changed to avoid the conflict.
>
> How exactly is the date or time changed, and by who?  Is the process
> always the same or is there discretion involved?
>
> > I have the schedule in csv format. I have been able to export it to
> sqlite3
> > as seen below and I have found all the conflicts, too.
> >
> > My dilemma is how to go about making sqlite3 alter the date, time, or
> exam
> > code if another trainee is scheduled at the same time and date with the
> same
> > test code.
> >
> > What is the proper approach to handle this?
>
> It depends on the current process of managing collisions.  If this is
> discretionary, then the approach for the program should be one where
> your program identifies the collisions, identifies suitable
> alternatives and then requests the user to supply the alternate
> date/time to resolve the conflict, repeating this for every conflict.
> If the collision management rules can be expressed entirely
> objectively then it might perhaps be fully automated.  There may also
> be a "best effort" type middle road where many/most cases can be
> automatically handled while some will require operator input.
>
> By the way, nice job using SQLite to do set based operations.  To move
> toward a solution, thinking off the top of my head, you will need to
> probably do something along the following lines:
> 1) For each collision detected in your previous work, find the details
> for that specific collision.
> 2) Determine which of the entries will keep the slot and remove it
> from the list of colliding entries
> 3) Find alternate slots for each of the remaining entries.
>
> 3) Will involve something like:
> 3.1) Determine list of suitable/available slots, suitably ordered
> 3.2) Update the colliding entry with a new selected date/time
> 3.3) Repeat for each collision.
>
> So 1) would involve another query, 2) involve input from the user, 3)
> likely involves 2 more queries, one for retrieving available slots and
> one for updating with a new date/time
>
> Finally I imagine you may want to write the entire lot back out to CSV
> (not sure if that's your goal or not.)
>
> Anyway, that's just a few thoughts off the top of my head.
>
> Walter
> ___
> Tutor maillist  -  Tutor@python.org 
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sqlite3 Dilemma

2012-07-30 Thread Khalid Al-Ghamdi
Damn! So its so serious they have a name for it! No wonder I was stumped
...

Any way thanks you guys have been super helpful.

بتاريخ الاثنين، ٣٠ يوليو، ٢٠١٢، جاء من Peter Otten
__pete...@web.de
:

> Khalid Al-Ghamdi wrote:
>
> > I am a teacher at an industrial training center. We have to conduct
> > hands-on exams (fixing pumps, etc). I review all the test schedules for
> > all the students (made by other teachers) to make sure there are no
> > clashes due to lack of ample supply of equipment or tools. Meaning no two
> > trainees are to have the same test at the same time. If this is the case,
> > then the date or time or test code have to be changed to avoid the
> > conflict.
> >
> > I have the schedule in csv format. I have been able to export it to
> > sqlite3 as seen below and I have found all the conflicts, too.
> >
> > My dilemma is how to go about making sqlite3 alter the date, time, or
> exam
> > code if another trainee is scheduled at the same time and date with the
> > same test code.
> >
> > What is the proper approach to handle this?
>
> I think what you have is a "constraint satisfaction problem". There are
> packages in Python that address it, but I have no experience with them and
> therefore cannot make any recommendations. This one
>
> http://pypi.python.org/pypi/constraint/
>
> ...has an example similar to your problem which may help you get started:
>
> http://www.logilab.org/3441
>
> > I'm using python 3 on windows.
>
> I see no mention of Python 3 on their site, so you probably have to resort
> to Python 2 should you end up with the solver mentioned above.
>
> > Below is how far I've gotten.
>
> I'd forget the database for the moment, but keep the code to verify the
> solution once you have arrived at it through other means.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Connecting to a DB via a function call

2012-11-11 Thread Khalid Al-Ghamdi
Hi,

Why is it that the following even though I call the below function? And how
do I write a function that makes connection that I can use to query my DB?

Traceback (most recent call last):
  File "C:/Python33/My Stuff/schedule_machine/schedule_machine01.py", line
19, in 
cur.execute('INSERT INTO schedule \
NameError: name 'cur' is not defined


   1. import csv
   2. import sqlite3
   3.
   4. def connect():
   5. conn = sqlite3.connect(':memory:')#use sch3.db or sch4.db  
   etc.
   6. cur = conn.cursor()
   7. cur.execute("create table schedule (teams integer, sn integer,
   badge integer ,name text, grp integer,\
   8.major text, track text, stage text,  tc text)")
   9.
   10. connect()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Adding items from a cursor to a dict?

2012-11-12 Thread Khalid Al-Ghamdi
Hi all,
How would you go about adding items from a cursor to a dictionary?

i tried this but to no avail:

>>> cur.execute('select * from schedule limit 10')

>>> for i in range(len(cur.fetchall())):
d[i]=cur.fetchall()[i]

Traceback (most recent call last):
  File "", line 2, in 
d[i]=cur.fetchall()[i]
IndexError: list index out of range

Thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help with a SQL Statement

2012-11-18 Thread Khalid Al-Ghamdi
Hi All,

The SQL statement below doesn't return anything.. and I don't know why...
I've used the parans but still no luck. Any Suggestions?

cur.execute("""select badge, name, stage, tc, major, package, subject,
course, sb_as from records where
   sb_as = 0 and (subject like 'Workshop&' or subject like
'Basic%' or subject like 'Introduction%') and
   (major not like 'Customer%' or major not like
'Warehouse%') order by tc""")

Thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with a SQL Statement

2012-11-18 Thread Khalid Al-Ghamdi
Hi, I found one typo in 'Workshop&' which should be 'Workshop%' but it
still gives results containing majors with 'Customer%' and 'Warehouse%' in
them...


On Sun, Nov 18, 2012 at 2:21 PM, Khalid Al-Ghamdi wrote:

> Hi All,
>
> The SQL statement below doesn't return anything.. and I don't know why...
> I've used the parans but still no luck. Any Suggestions?
>
> cur.execute("""select badge, name, stage, tc, major, package, subject,
> course, sb_as from records where
>sb_as = 0 and (subject like 'Workshop&' or subject like
> 'Basic%' or subject like 'Introduction%') and
>(major not like 'Customer%' or major not like
> 'Warehouse%') order by tc""")
>
> Thanks
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] There's a Programmer in Me

2013-02-26 Thread Khalid Al-Ghamdi
Hi All,

I'm not a programmer by profession, but I want to learn python. I've got
lots of Ideas that want to realize, but I always run into these
stupid hiccups where I follow the tutorials and something stupid
(known/unkown) is causing things not to work ... frustration ensues...

After more than 2 years (on and off) I've got the basics down and
have written some scripts, but I want some place online where a live person
can tutor me to the next level. Any good suggestions?

As always, many thanks for your great advice.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] There's a Programmer in Me

2013-02-26 Thread Khalid Al-Ghamdi
Hi all and thanks for your suggestions,

I was thinking of something like a virtual classroom where I can get live
mentoring and answers to my inquiries in a one on one or small group
setting.

Thanks

On Tuesday, February 26, 2013, Mark Lawrence wrote:

> On 26/02/2013 13:57, Tim Golden wrote:
>
>> On 26/02/2013 13:54, Mark Lawrence wrote:
>>
>>> On 26/02/2013 13:02, Khalid Al-Ghamdi wrote:
>>>
>>>> Hi All,
>>>>
>>>> I'm not a programmer by profession, but I want to learn python. I've got
>>>> lots of Ideas that want to realize, but I always run into these
>>>> stupid hiccups where I follow the tutorials and something stupid
>>>> (known/unkown) is causing things not to work ... frustration ensues...
>>>>
>>>> After more than 2 years (on and off) I've got the basics down and
>>>> have written some scripts, but I want some place online where a live
>>>> person can tutor me to the next level. Any good suggestions?
>>>>
>>>> As always, many thanks for your great advice.
>>>>
>>>>
>>> http://pythonmentors.com/
>>>
>>>
>> Umm. No. Sorry, Mark, but that site and the core-mentorship list it
>> advertises are intended for progammers who want to be helped in the
>> development *of* Python, not development *in* Python. Ie, otherwise
>> experienced programmers who are unfamiliar with the Python codebase.
>>
>> TJG
>>
>>
> Umm.  No.  Sorry, Tim, but nowhere does the OP state that he wants to
> develop in Python, hence "The mission of the Python Core Mentor Program is
> to provide an open and welcoming place to connect students, programmers –
> and anyone interested in contributing to the Python Core development."
> seems to me an excellent fit for "some place online where a live person can
> tutor me to the next level".
>
> --
> Cheers.
>
> Mark Lawrence
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] There's a Programmer in Me

2013-02-27 Thread Khalid Al-Ghamdi
Thanks everyone.

On Wednesday, February 27, 2013, Femi Banjo wrote:

> coursera, udacity & edx all have decent Python  courses for beginners and
> very good support on forums etc and they're all free
>
> > Date: Wed, 27 Feb 2013 01:10:07 -0800
> > From: fo...@yahoo.com 
> > To: eryk...@gmail.com 
> > CC: tutor@python.org 
> > Subject: Re: [Tutor] There's a Programmer in Me
> >
> >
> >
> > > On Tue, Feb 26, 2013 at 4:00 PM, Albert-Jan Roskam 
> > > >
>
> > > wrote:
> > >>
> > >> What I like about R: if I do 'print(func)' (or fix(func)), it
> > > prints the
> > >> source code of the function. It would be cool if Python had something
> > >> similar. Instead Python prints the not-so-informative
> > >> 
> > >
> > > You can use inspect.getsource(obj) if obj is a module, class, method,
> > > function, traceback, frame, or code that has a source file (e.g.
> > > __file__, co_filename) and is defined normally (e.g. class, def):
> > >
> > > >>> import inspect
> > > >>> def printsrc(obj): print inspect.getsource(obj)
> > >
> > > >>> import antigravity
> > > >>> printsrc(antigravity)
> > >
> > > import webbrowser
> > >
> > > webbrowser.open(http://xkcd.com/353/)
> >
> > Ahh, thank you! I like the %psource magic word, but until I get IPython
> installed in the office I'll use inspect.getsource.
> > import inspect, soul
> > print inspect.getsource(soul.getsoul)
> > import webbrowser
> > webbrowser.open(http://xkcd.com/413/)  ;-))
> >
> > ___
> > Tutor maillist - Tutor@python.org  'Tutor@python.org');>
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] producing PDF files

2013-06-11 Thread Khalid Al-Ghamdi
Hi,

Do you know of a python module for converting text files to PDF format?

thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sqlite question

2013-06-11 Thread Khalid Al-Ghamdi
Hi,

I have a dictionary with keys as employee badges and values as their names.
Both key and value are strings.

I want to read the badges from a sql select and use that to look up the
names in the dictionary. But since the result is a tuple, it doesnt' work.

how can i overcome this?


   1. >>> for data in cur.execute('select badge from sched'):
   2. r_data()[data]
   3.
   4.
   5. Traceback (most recent call last):
   6.   File "", line 2, in 
   7. r_data()[data]
   8. KeyError: (80385,)

   PS: the r_data () above is just a func that returns the before mentioned
   dictionary. Here is r_data().

   1. def r_data():
  2. d={}
  3. with open('data.csv') as f:
  4. reader = csv.reader(f)
  5. for sn, badge, name, grp, major, track, stage, tc, subject,
   course in reader:
  6. d[badge]=name
  7. return d
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Using __init__ to return a value

2013-06-12 Thread Khalid Al-Ghamdi
Hi,

Why doesn't this work? And is there way to have an
object immediately return a value or object once it is instantiated with
using a method call?


   1. >>> class k:
   2. def __init__(self,n):
   3. return n*n
   4.
   5.
   6. >>> khalid=k(3)
   7. Traceback (most recent call last):
   8.   File "", line 1, in 
   9. khalid=k(3)
   10. TypeError: __init__() should return None, not 'int'
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Regarding Exceptions

2014-02-17 Thread Khalid Al-Ghamdi
Hi,
in the following snippet, why is it I don't need to create an Exception
object and I can use the class directly in raise my custom exception?

http://pastebin.com/embed_iframe.php?i=7ANcvLHR";
style="border:none;width:100%">
Thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Regarding Exceptions

2014-02-17 Thread Khalid Al-Ghamdi
Hi,

Why is it i can use mu custom class exception without creating an exception
object first?

Thanks


   1. class ShortInputException(Exception): def __init__(self, length,
atleast):
   2. Exception.__init__(self)
   3. self.length = length
   4. self.atleast = atleast
   5. try:
   6. text = input() if len(text) < 3:
   7. raise ShortInputException(len(text), 3) # Other work can continue as
   usual here
   8. except EOFError:
   9. print()
   10. except ShortInputException as ex:
   11. print(\
   12. .format(ex.length, ex.atleast)) else:
   13. print()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] OCR Library

2014-02-18 Thread Khalid Al-Ghamdi
Hi,

Do you have any recommendations regarding a good OCR library (preferably
Py3)?

Thanks
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor