MySQLdb not allowing hyphen
Hello All,
I noticed that MySQLdb not allowing hyphen may be way to prevent injection
attack.
I have something like below:
"insert into reviews(message, title)values('%s', '%s')" %( "We don't know
where to go","We can't wait till morrow" )
ProgrammingError(1064, "You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right
syntax to use near 't know where to go.
How do I work around this error?
Regards,
Emeka
--
*Satajanus Nig. Ltd
*
--
http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb not allowing hyphen
Dennis , Chris
Thanks so much!
On Mon, Feb 6, 2012 at 1:23 AM, Dennis Lee Bieber wrote:
> On Mon, 6 Feb 2012 00:41:24 +0200, Emeka wrote:
>
> >Hello All,
> >
> >I noticed that MySQLdb not allowing hyphen may be way to prevent injection
> >attack.
>
> What hyphen?
>
> >I have something like below:
> >
> >"insert into reviews(message, title)values('%s', '%s')" %( "We don't know
> >where to go","We can't wait till morrow" )
> >
>
> >How do I work around this error?
>
> Very simple... DON'T QUOTE PLACEHOLDERS AND USE MySQLdb
> parameterized queries.
>
> csr.execute("insert into reviews (message, title) values (%s, %s)",
>( "We don't know where to go",
>"We can't wait till morrow" ) )
>
>The whole purpose of parameterized queries is that the .execute()
> logic will SAFELY wrap the supplied values with quotes AND escape any
> problem characters within the value.
>
>The reason you got an error was not a hyphen (there are no hyphens
> in your example) but rather that you closed the quote. Your generated
> SQL was:
>
> insert into reviews (message, title) values ('We don't know where to
> go', 'We can't wait till morrow')
>
> which means a string of:
>"We don"
> SQL garbage
> t know where to go
> string
>", "
> SQL garbage
>We can
> and another string
>"t wait till morrow"
> --
>Wulfraed Dennis Lee Bieber AF6VN
>[email protected]://wlfraed.home.netcom.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
*Satajanus Nig. Ltd
*
--
http://mail.python.org/mailman/listinfo/python-list
Id of methods
Hell All,
I am trying to see if I could get more of Python without being insane.
class Boo(object):
def __init__(self , moon, sun):
self.moon = moon
self.sun = sun
def daf(self):
return self.sun + self.moon
def ball(self):
return self.sun * self.moon
print Boo.__dict__
{'__module__': '__main__', 'ball': , 'daf':
, '__dict__ ..}
print hex(id(Boo.daf))
0x27de5a0
My question is why is it that the id of Boo.daf is different from daf's
hex value in the above dict?
Regards, \Emeka
*Satajanus Nig. Ltd
*
--
http://mail.python.org/mailman/listinfo/python-list
Undoing character read from file
Hello All, I know about seek and tell while using readline. What about if I am using read, and I want to undo the last character I just read(to return it back to the stream). How do I achieve this? Regards, \Emeka *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
Re: Undoing character read from file
Neil, Thanks. Could you throw a simple example? Regards, \Emeka On Fri, Feb 17, 2012 at 3:12 PM, Neil Cerutti wrote: > On 2012-02-16, MRAB wrote: > > On 16/02/2012 23:10, Emeka wrote: > >> Hello All, > >> > >> I know about seek and tell while using readline. What about if I am > >> using read, and I want to undo the last character I just read(to return > >> it back to the stream). How do I achieve this? > >> > > Try: > > > > f.seek(-1, 1) > > > > It seeks -1 relative to the current position (the second > > argument defaults to 0 for relative to start of file). > > Unless it's a stream opened in binary mode this will not work. > You'd need to maintain a n-character length buffer instead, with > n being the maximum number of characters you'd like to be able to > put back. > > -- > Neil Cerutti > -- > http://mail.python.org/mailman/listinfo/python-list > -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
Re: Undoing character read from file
Hello All,
Say I have something like this:
mfile = open("cc.txt", "rb")
mcount = 0
mset = False
while True:
c = mfile.read(1)
if c == "e" and mset is True and mcount == 0:
print c
mfile.seek(-1,1)
mcount = 1
continue
elif c == "e" and mset is False and mcount == 0:
print c
mfile.seek(-1, 0)
mcount = 1
continue
elif c == "e" and mcount == 1:
print c
mcount = 0
continue
print c
if mset is False:
mset = True
if len(c) == 0:
break
cc.txt
foor the this the been we hate to sh wiukr bee here today. But who are we
to question
him concerning this issue.
Is the above code the right way?
Regards, \Emeka
On Sat, Feb 18, 2012 at 5:17 AM, Emeka wrote:
> Neil,
>
> Thanks. Could you throw a simple example?
>
> Regards, \Emeka
>
>
> On Fri, Feb 17, 2012 at 3:12 PM, Neil Cerutti wrote:
>
>> On 2012-02-16, MRAB wrote:
>> > On 16/02/2012 23:10, Emeka wrote:
>> >> Hello All,
>> >>
>> >> I know about seek and tell while using readline. What about if I am
>> >> using read, and I want to undo the last character I just read(to return
>> >> it back to the stream). How do I achieve this?
>> >>
>> > Try:
>> >
>> > f.seek(-1, 1)
>> >
>> > It seeks -1 relative to the current position (the second
>> > argument defaults to 0 for relative to start of file).
>>
>> Unless it's a stream opened in binary mode this will not work.
>> You'd need to maintain a n-character length buffer instead, with
>> n being the maximum number of characters you'd like to be able to
>> put back.
>>
>> --
>> Neil Cerutti
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
>
> --
> *Satajanus Nig. Ltd
>
>
> *
>
--
*Satajanus Nig. Ltd
*
--
http://mail.python.org/mailman/listinfo/python-list
Re: Udacity CS 101
Well, I checked unit 2 out the other day. It is indeed of poor standard and to some extend a waste of time for me. However, I see it as another way of having fun. On Sat, Mar 3, 2012 at 5:47 AM, Josh English wrote: > On Monday, February 27, 2012 6:37:25 PM UTC-8, Ray Clark wrote: > > > > You have to remember that this course assumes no prior computer > > programming knowledge. > > > > I agree, it is starting out very basic. Give it some more time. > > These guys have PhDs from MIT and/or have taught at Stanford. They > > know what they are doing. > > It seems to me that they're not starting with good Python practices, > really, or even the terminology I'd expect. > -- > http://mail.python.org/mailman/listinfo/python-list > -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
Is Python Lazy?
Hello All, Could one say that generator expressions and functions are Python way of introducing Lazy concept? Regards, \Emeka -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
Joining Strings
Hello All,
import urllib.request
import re
url = 'https://www.everyday.com/
req = urllib.request.Request(url)
resp = urllib.request.urlopen(req)
respData = resp.read()
paragraphs = re.findall(r'\[(.*?)\]',str(respData))
for eachP in paragraphs:
print("".join(eachP.split(',')[1:-2]))
print("\n")
I got the below:
"Coke - Yala Market Branch""NO. 113 IKU BAKR WAY YALA"""
But what I need is
'Coke - Yala Market Branch NO. 113 IKU BAKR WAY YALA'
How to I achieve the above?
Regards Janus
--
P.S Please join our groups*: *[email protected]
* or *[email protected] These are platforms for learning
and sharing of knowledge.
www.satajanus.com | *Satajanus Nig.
Ltd*
--
https://mail.python.org/mailman/listinfo/python-list
Re: Joining Strings
Jussi,
Thanks it worked when parsed with json.load. However, it needed this
decode('utf'):
data = json.loads(respData.decode('utf-8'))
On Thu, Apr 7, 2016 at 6:01 AM, Jussi Piitulainen <
[email protected]> wrote:
> Emeka writes:
>
> > Hello All,
> >
> > import urllib.request
> > import re
> >
> > url = 'https://www.everyday.com/
> >
> >
> >
> > req = urllib.request.Request(url)
> > resp = urllib.request.urlopen(req)
> > respData = resp.read()
> >
> >
> > paragraphs = re.findall(r'\[(.*?)\]',str(respData))
> > for eachP in paragraphs:
> > print("".join(eachP.split(',')[1:-2]))
> > print("\n")
> >
> >
> >
> > I got the below:
> > "Coke - Yala Market Branch""NO. 113 IKU BAKR WAY YALA"""
> > But what I need is
> >
> > 'Coke - Yala Market Branch NO. 113 IKU BAKR WAY YALA'
> >
> > How to I achieve the above?
>
> A couple of things you could do to understand your problem and work
> around it: Change your code to print(eachP). Change your "".join to
> "!".join to see where the commas were. Experiment with data of that form
> in the REPL. Sometimes it's good to print repr(datum) instead of datum,
> though not in this case.
>
> But are you trying to extract and parse paragraphs from a JSON response?
> Do not use regex for that at all. Use json.load or json.loads to parse
> it properly, and access the relevant data by indexing:
>
> x = json.loads('{"foo":[["Weather Forecast","It\'s Rain"],[]]}')
>
> x ==> {'foo': [['Weather Forecast', "It's Rain"], []]}
>
> x['foo'] ==> [['Weather Forecast', "It's Rain"], []]
>
> x['foo'][0] ==> ['Weather Forecast', "It's Rain"]
> --
> https://mail.python.org/mailman/listinfo/python-list
>
--
P.S Please join our groups*: *[email protected]
* or *[email protected] These are platforms for learning
and sharing of knowledge.
www.satajanus.com | *Satajanus Nig.
Ltd*
--
https://mail.python.org/mailman/listinfo/python-list
Code Review
Hello All, While learning Python I put together another Text Twist. I would want somebody to go through it and comment. https://github.com/janus/Text-Twist -- Regards, Emeka * * -- http://mail.python.org/mailman/listinfo/python-list
Re: Code Review
Philipp,
Thanks so much for your time and comment. I will re-work my code
accordingly.
Regards,
Emeka
On Sat, Sep 17, 2011 at 12:19 PM, Philipp Hagemeister wrote:
> Instead of comments, you can often use docstrings
> (http://www.python.org/dev/peps/pep-0257/ ):
>
> This is hard to read due to the indentation, and cannot be accessed
> programmatically:
>
> #Update the GUI
>def update_gui(self, new_word):
>
> Instead, use this:
>
>def update_gui(self, new_word):
>"Update the GUI."
>
> Now, you can use help(Message) to get information about the method.
> You'll notice "Update the GUI." is not helpfull at all for a method
> called update_gui. Comments (and docstrings) that reproduce the method
> name are not useful.
>
> A couple of minor things:
>
> * If you delete code, delete it, don't comment it out.
> * Use newlines between two methods. Compare
> def a(self):
> pass
> def b(self):
> pass
> def c(self):
> pass
>
> with
>
> def a(self):
> pass
>
> def b(self):
> pass
>
> def c(self):
> pass
>
> The latter looks neat and not nearly as crammed as the former.
> * Don't use newlines where they shouldn't be, for example in
>if val == 0:
>
> label.unbind('')
> * Even if it's just the comments, typos make a very bad impression of a
> coder and the code. I'd automatically assume lots of bugs and untested
> code when I see more than the occasional typo.
> * GUI programming is fun, but does not lend itself to structured
> programming and good practices. You should never use global. Instead,
> have an object encapsulating the state and pass that object to the
> method itself or its object.
> * Don't commit .pyc files, they're totally useless. Since python 2.6,
> you can add the following in your .bashrc to make python not create them:
>
> export "PYTHONDONTWRITEBYTECODE=dont"
>
> In git, you can add the following in your project's .gitignore or
> ~/.gitignore_global:
>
> *.pyc
>
> [More on .gitignore: http://help.github.com/ignore-files/ ]
> * Otherwise, the code looks pretty good for a beginner. You may,
> however, want to replace
>
> def word_not_found(word):
> if word in searchedwordset:
>return 0
> else:
>return 1
>
> with just:
>
> def word_not_found(word):
> return word not in searchedwordset
>
> (or just skip this method and write word not in searchedwordset).
>
> Cheers,
>
> Philipp
>
>
>
> Emeka wrote:
> > Hello All,
> >
> > While learning Python I put together another Text Twist. I would want
> > somebody to go through it and comment.
> > https://github.com/janus/Text-Twist
> >
> >
>
>
>
--
*Satajanus Nig. Ltd
*
--
http://mail.python.org/mailman/listinfo/python-list
TK + MVC
Hello All, I need a basic example where MVC pattern is used with Python TK. Regards, Emeka -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
Re: TK + MVC
Greg, Do you have an example where the Controller is connected? Regards, EMeka On Sun, Oct 2, 2011 at 4:40 AM, Gregory Ewing wrote: > Alexander Kapps wrote: > > But I think a simple (and quick 'n' dirty) Tk MVC example can look like >> this: >> > > The Controller doesn't seem to add any value in that example. > You might as well connect the Model and Views directly to > each other. > > -- > Greg > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
Re: TK + MVC
Alex, The question was not meant for you. I was responding to Greg's comment. Regards, Emeka On Mon, Oct 3, 2011 at 12:14 AM, Alexander Kapps wrote: > On 03.10.2011 00:15, Emeka wrote: > >> Greg, >> >> Do you have an example where the Controller is connected? >> > > What do you mean? In my example, the Controller *is* connected (to both the > View and the Model.) > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
Working with Descriptors
Hello All, How do I get the __set__ to work here? import random class Die(object): def __init__(self, sides=6): self.sides = sides def __get__(self, instance, owner): return int(random.random() * self.sides) + 1 def __set__(self, instance, value): instance.__dict__[self.side] = value class Game(object): d6 = Die() d10 = Die(sides=10) d20 = Die(sides=20) Game.d3 = 90 (This failed) Regards, Emeka -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
Please explain this for me
Hello All, v = [] def add_to_list(plist): u = plist.append(90) return u add_to_list(v) # This function call returns nothing Could someone explain why this function call will return nothing? v = [90] # Object values are passed by reference This one is clear to me add_to_list([]) This one returns nothing, why? Regards, Emeka -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
Re: Please explain this for me
Noah, Calvin Thanks so much! Regards, Emeka On Wed, Dec 21, 2011 at 6:57 AM, Noah Hall wrote: > On Wed, Dec 21, 2011 at 4:39 AM, Emeka wrote: > > > > Hello All, > > > v = [] > > > > def add_to_list(plist): > > u = plist.append(90) > > return u > > > > add_to_list(v) # This function call returns nothing > > Could someone explain why this function call will return nothing? > > It's because add_to_list returns the value returned from plist.append > stored in u. > append changes a list in place and returns nothing. Functions that > return nothing return None. This is why it'll be None - u is None > because append returns None. > > > > add_to_list([]) > > This one returns nothing, why? > > It's because the object [] here has no name, so that you have no way > to refer to it after the function changes it, since it changes it in > place. It gets eaten by Python, never to be seen again. > -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
globals function
Hello All, What is the downside of using globals function Regards, Janus -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
Re: Get Class properties
Hello All, I have seen what I am looking for.. __dict__. Thanks! Regards, Janus On Wed, Dec 28, 2011 at 1:05 PM, Emeka wrote: > > Hello All, > > Say I have a class like below > > class Town: > state = StateClass() > cities = CityClass() > > > Is there way to introspect such that one can list the properties keys and > their values in such a way that it would look like playing around > dictionary ? > > Regards, > Janus > -- > *Satajanus Nig. Ltd > > > * > -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
Get Class properties
Hello All, Say I have a class like below class Town: state = StateClass() cities = CityClass() Is there way to introspect such that one can list the properties keys and their values in such a way that it would look like playing around dictionary ? Regards, Janus -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
Re: Get Class properties
Chris, Thanks a million! Regards, Emeka On Thu, Dec 29, 2011 at 1:27 AM, Chris Angelico wrote: > On Wed, Dec 28, 2011 at 11:13 PM, Emeka wrote: > > Hello All, > > > > I have seen what I am looking for.. __dict__. > > > > Yep! You may also want to look at the dir() function. > > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list > -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
dict_to_xml
Hello All, I have a dictionary object I would like to convert to xml. Could some assist with the link to libs to use? Or good examples. Regards, Janus -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
MySQLdb Error
Hello All, I got the below error why trying to create tables of the fly. for item in ['CREATE TABLE AddressTables ( AddressTables_id int (9) unsigned primary key auto_increment not null, city_name char(40) , state_name varchar, street_number int, country_name varchar, street_name char(40) , user_name char(40) references usertables(name))', 'CREATE TABLE UserTables ( age int, UserTables_id int (9) unsigned primary key auto_increment not null, name char(40) , place_of_birth varchar)']: cursor.execute(item) I receive the following errors. File "mor.py", line 98, in cursor.execute(item) File "/usr/lib/pymodules/python2.7/MySQLdb/cursors.py", line 166, in execute self.errorhandler(self, exc, value) File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 35, in defaulterrorhandler raise errorclass, errorvalue _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' street_number int, country_name varchar, street_name char(40) , user_name ch' at line 1") * Regards,* *Emeka * -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb Error
Thanks. Regards, Janus On Wed, Jan 11, 2012 at 7:12 PM, Dennis Lee Bieber wrote: > On Wed, 11 Jan 2012 09:57:43 +0200, Emeka wrote: > > > >_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL > >syntax; check the manual that corresponds to your MySQL server version for > >the right syntax to use near ' street_number int, country_name varchar, > > street_name char(40) , user_name ch' at line 1") > >* > > > >Per http://dev.mysql.com/doc/refman/5.1/en/create-table.html and > http://dev.mysql.com/doc/refman/5.1/en/char.html VARCHAR fields > /require/ the maximum length of the field to be defined. Length appears > optional for CHAR -- probably defaulting to 1 character. > -- >Wulfraed Dennis Lee Bieber AF6VN >[email protected]://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
Python lib for creating Database tables
Hello All, I just made something pretty simple that I intend to use while creating database tables. It is still in the basic form, and much needs to be added. However, I use introspection to make it a bit easier and less work on the user. I would want my code to be reviewed by this great group. I look forward to your feedback and comments. https://github.com/janus/cheeta Thanks in advance! Regards, Emeka * * -- http://mail.python.org/mailman/listinfo/python-list
C to Python
Hello All, I am finding it difficult getting my head around PyObject_CallObject(x,y). I need a gentle and thorough introduction to it. I also need examples. Could someone come to my need? Thanks. Janus. -- http://mail.python.org/mailman/listinfo/python-list
Fwd: PyArg_ParseTupleAndKeywords in Python3.1
static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds)
{
int a=65, b=66;
char *kwlist[] = {"a", "b", NULL};
I am yet to understand what kwlist pointer does and why it is needed?
if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a,
&b))
return NULL;
return Py_BuildValue("(CC)", a, b);
}
Regards,
Emeka
The following code seems to work fine for me:
static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds)
{
int a=65, b=66;
char *kwlist[] = {"a", "b", NULL};
I am yet to understand what kwlist pointer does and why it is needed?
if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a,
&b))
return NULL;
return Py_BuildValue("(CC)", a, b);
}
Regards,
Emeka
The default values seem to remain as 'A' and 'B'
On Fri, Dec 18, 2009 at 8:17 AM, casevh wrote:
> On Dec 17, 11:14 am, Joachim Dahl wrote:
> > In the Ubuntu 9.10 version of Python 3.1 (using your patch), there's a
> > related bug:
> >
> > >>> foo(b='b')
> >
> > will set the value of a in the extension module to zero, thus clearing
> > whatever
> > default value it may have had. In other words, the optional character
> > arguments
> > that are skipped seem to be nulled by PyArg_ParseTupleAndKeywords().
>
> The following code seems to work fine for me:
>
> static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds)
> {
> int a=65, b=66;
> char *kwlist[] = {"a", "b", NULL};
>if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a,
> &b))
>return NULL;
> return Py_BuildValue("(CC)", a, b);
> }
>
> The default values seem to remain as 'A' and 'B'.
>
> >>> foo()
> ('A', 'B')
> >>> foo(b='b')
> ('A', 'b')
> >>> foo()
> ('A', 'B')
> >>> foo('a')
> ('a', 'B')
> >>> foo('a', b='b')
> ('a', 'b')
> >>> foo()
> ('A', 'B')
> >>>
>
> casevh
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: PyArg_ParseTupleAndKeywords in Python3.1
char *kwlist[] = {"a", "b", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a,
&b))
I am yet to understand what pointer kwlist[] does and why it is needed?
Regards,
Emeka
On Fri, Dec 18, 2009 at 8:17 AM, casevh wrote:
> On Dec 17, 11:14 am, Joachim Dahl wrote:
> > In the Ubuntu 9.10 version of Python 3.1 (using your patch), there's a
> > related bug:
> >
> > >>> foo(b='b')
> >
> > will set the value of a in the extension module to zero, thus clearing
> > whatever
> > default value it may have had. In other words, the optional character
> > arguments
> > that are skipped seem to be nulled by PyArg_ParseTupleAndKeywords().
>
> The following code seems to work fine for me:
>
> static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds)
> {
> int a=65, b=66;
> char *kwlist[] = {"a", "b", NULL};
>if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a,
> &b))
>return NULL;
> return Py_BuildValue("(CC)", a, b);
> }
>
> The default values seem to remain as 'A' and 'B'.
>
> >>> foo()
> ('A', 'B')
> >>> foo(b='b')
> ('A', 'b')
> >>> foo()
> ('A', 'B')
> >>> foo('a')
> ('a', 'B')
> >>> foo('a', b='b')
> ('a', 'b')
> >>> foo()
> ('A', 'B')
> >>>
>
> casevh
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: PyArg_ParseTupleAndKeywords in Python3.1
Case,
Thanks so much! However, I am still confused. This is what I understood;
foo (a = "a", b = "b") so function , foo, has default values which are "a"
and "b". pointer kwlist[] is a way of specifying default values .
Regards,
Emeka
On Fri, Dec 18, 2009 at 3:02 PM, Case Vanhorsen wrote:
> On Fri, Dec 18, 2009 at 2:26 AM, Emeka wrote:
> >char *kwlist[] = {"a", "b", NULL};
> >if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a,
> > &b))
> > I am yet to understand what pointer kwlist[] does and why it is needed?
> > Regards,
> > Emeka
>
> foo is designed to accept two arguments that can be specified by
> either position or name. kwlist contains the legal keyword names. In
> this example, the legal keywords are 'a' and 'b'. That they match the
> names of the C variables is just a lucky coincidence. If you want to
> change the keyword names to 'foo' and 'bar', you would just use char
> *kwlist[]={"foo", "bar", NULL}.
>
> casevh
> >
> > On Fri, Dec 18, 2009 at 8:17 AM, casevh wrote:
> >>
> >> On Dec 17, 11:14 am, Joachim Dahl wrote:
> >> > In the Ubuntu 9.10 version of Python 3.1 (using your patch), there's a
> >> > related bug:
> >> >
> >> > >>> foo(b='b')
> >> >
> >> > will set the value of a in the extension module to zero, thus clearing
> >> > whatever
> >> > default value it may have had. In other words, the optional character
> >> > arguments
> >> > that are skipped seem to be nulled by PyArg_ParseTupleAndKeywords().
> >>
> >> The following code seems to work fine for me:
> >>
> >> static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds)
> >> {
> >>int a=65, b=66;
> >>char *kwlist[] = {"a", "b", NULL};
> >>if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a,
> >> &b))
> >>return NULL;
> >>return Py_BuildValue("(CC)", a, b);
> >> }
> >>
> >> The default values seem to remain as 'A' and 'B'.
> >>
> >> >>> foo()
> >> ('A', 'B')
> >> >>> foo(b='b')
> >> ('A', 'b')
> >> >>> foo()
> >> ('A', 'B')
> >> >>> foo('a')
> >> ('a', 'B')
> >> >>> foo('a', b='b')
> >> ('a', 'b')
> >> >>> foo()
> >> ('A', 'B')
> >> >>>
> >>
> >> casevh
> >> --
> >> http://mail.python.org/mailman/listinfo/python-list
> >
> >
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: PyArg_ParseTupleAndKeywords in Python3.1
Okay if that is the case, why do we need it? By having int a = 65, b = 66 ,
why should we also have *kwlist[]?
static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds)
{
int a=65, b=66;
char *kwlist[] = {"a", "b", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a,
&b))
return NULL;
return Py_BuildValue("(CC)", a, b);
}
On Fri, Dec 18, 2009 at 9:31 PM, casevh wrote:
> On Dec 18, 10:28 am, Joachim Dahl wrote:
> > My mistake seems to be that I declared
> >
> > char a, b;
> >
> > instead of
> >
> > int a, b;
> >
> > Thank you for sorting this out.
> >
> > Joachim
>
> I think you need to initialize them, too.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: Creating Classes
Hello Dave > > There are more complex things that can go on, like creating "bound" > function objects, but I think this should get you pretty far. > > Could explain the complex things for me? Regards, Janus -- http://mail.python.org/mailman/listinfo/python-list
New hire
Hello All, I am new to python , and my aim is to use it to write sugar-based applications on XO(OLPC). I am not new to programming in general, I would want to know the best route to take in learning python. I have background in FP and Imperative languages. Regards, Emeka -- http://mail.python.org/mailman/listinfo/python-list
Tkinter's unbind method
Hello All I have an uncompleted version of a game http://pastebin.com/gkhTaYPZ I am trying to code I have struggled to make method unbind work. But it has refused to listen to me. Could someone come to my help? Regards, Emeka http://pastebin.com/gkhTaYPZ -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
Re: Introducing Kids to Programming: 2 or 3?
Marco, This is a great news coming out of Africa. I would very much like to see this your success story replicate across the continent. I would like to participate and to have your programs for my country, Nigeria. >From what you asked for, I would say that those kids should be part of the future and not the past. So, go for Python 3. Being new to programming, what matters most is learning programming and not the minor syntactical differences. Get them to understand the real thing and they would build up from there. Regards , Emeka On Mon, Sep 27, 2010 at 4:48 PM, Marco Gallotta wrote: > Hi there > > I'm sure you get a lot of "2 or 3" questions, but here's another. > Umonya [1] uses Python to introduce school kids to programming. The > initiative is only 15 months old and up till now we've been using > existing notes and exercises and thus Python 2. But we're at the stage > where we can either stick with 2 for the next few years, or go to 3 > now. > > We received a grant from Google to reach 1,000 kids in South Africa > with our course in 2011. People have also shown interest in running > the course in Croatia, Poland and Egypt. We're also eyeing developing > African countries in the long-term. As such, we're taking the time now > to write our very own specialised course notes and exercises, and we > this is why we need to decide *now* which path to take: 2 or 3? As we > will be translating the notes we'll probably stick with out choice for > the next few years. > > Since these are kids, we feel the nice changes in 3 such as removing > integer division will help in teaching. It will also remove confusion > when they go to download Python and grab the latest version. Since > they're just starting, chances are almost none will be hit by the > limited library support for at least a year or two. They will, > however, be hit by the confusion of seeing Python 2 code all over the > web. > > We're tending towards 3, but I am a little cautious myself. > > Marco > > [1] http://umonya.co.za > > -- > Marco Gallotta > MSc Student > Department of Computer Science, University of Cape Town > people.cs.uct.ac.za/~mgallott <http://people.cs.uct.ac.za/%7Emgallott> | > marco-za.blogspot.com > marco AT gallotta DOT co DOT za | 073 170 | 021 552 2731 > -- > http://mail.python.org/mailman/listinfo/python-list > -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
Background image with Tkinter
Hello All, I know this is pretty easy to do, but I was not able to to do it because I am new to GUI and Python. I am using grid to manager my layout and I would like to add background image to one of my cells (say row=1 column=3), I intend to have a label (text ) written on top of the image. For now, I would like to stick with Tkinter, I checked out PIL. It seems like support for Python27 is jet to be included. Regards, Emeka -- *Satajanus Nig. Ltd * -- http://mail.python.org/mailman/listinfo/python-list
Error message
Please I downloaded Python 3.5 (32 bit) for Windows software. I installed it but it keeps giving me an error message that a file was not found and I should please re-install to fix the problem. I've tried that severally but to no avail. Please what can I do or should I just install the 2.7 version? Thank you -- https://mail.python.org/mailman/listinfo/python-list
