What is the reason from different output generate using logical 'and' and 'or' operator in Python 3.10.8

2022-11-07 Thread ICT Ezy
Please explain how to generate different output in following logical operations
>>> 0 and True
0
>>> 0 or True
True
>>> 1 and True
True
>>> 1 or True
1
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Indentation example?

2016-06-13 Thread ICT Ezy
On Monday, June 13, 2016 at 3:09:15 AM UTC+5:30, Marc Dietz wrote:
> On Sun, 12 Jun 2016 08:10:27 -0700 ICT Ezy wrote:
> 
> > Pl explain with an example the following phase "Indentation cannot be
> > split over multiple physical lines using backslashes; the whitespace up
> > to the first backslash determines the indentation" (in 2.1.8.
> > Indentation of Tutorial.)
> > I want to teach my student that point using some examples.
> > Pl help me any body?
> 
> Hi!
> 
> This is my very first post inside the usenet. I hope I did understand 
> this right, so here is my answer. :)
> 
> I assume, that you do understand the concept of indentation inside Python 
> code. You can concatenate lines with a backslash. These lines work as if 
> they were only one line. For example:
> 
> >>> print ("This is a very long"\
> ... " line, that got "\
> ... "diveded into three lines.")
> This is a very long line, that was diveded into three.
> >>>
> 
> Because the lines get concatenated, one might think, that you could 
> divide for example 16 spaces of indentation into one line of 8 spaces 
> with a backslash and one line with 8 spaces and the actual code.
> Your posted text tells you though, that you can't do this. Instead the 
> indentation would be considered to be only 8 spaces wide.
> 
> I hope this helped a little. :)
> 
> Cheers 
> Marc.

Thank you very much your explaination here
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Indentation example?

2016-06-12 Thread ICT Ezy
On Sunday, June 12, 2016 at 9:36:16 PM UTC+5:30, Steven D'Aprano wrote:
> On Mon, 13 Jun 2016 01:10 am, ICT Ezy wrote:
> 
> > Pl explain with an example the following phase
> > "Indentation cannot be split over multiple physical lines using
> > backslashes; the whitespace up to the first backslash determines the
> > indentation" (in 2.1.8. Indentation of Tutorial.) I want to teach my
> > student that point using some examples. Pl help me any body?
> 
> 
> Good indentation:
> 
> def function():
> # four spaces per indent
> print("hello")
> print("goodbye")
> 
> 
> Bad indentation:
> 
> def function():
> # four spaces per indent
> print("hello")  # four spaces
>   \
>   print("goodbye")  # two spaces, then backslash, then two more
> 
> 
> The second example will be a SyntaxError.
> 
> 
> 
> -- 
> Steven
Thank you very much your example 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Indentation example?

2016-06-12 Thread ICT Ezy
On Sunday, June 12, 2016 at 9:46:00 PM UTC+5:30, Ned Batchelder wrote:
> On Sunday, June 12, 2016 at 11:10:39 AM UTC-4, ICT Ezy wrote:
> > Pl explain with an example the following phase
> > "Indentation cannot be split over multiple physical lines using 
> > backslashes; the whitespace up to the first backslash determines the 
> > indentation" (in 2.1.8. Indentation of Tutorial.)
> > I want to teach my student that point using some examples.
> > Pl help me any body?
> 
> For what it's worth, that sentence isn't in the tutorial, it's in the
> reference manual, which has to mention all sorts of edge cases that most
> people will likely never encounter.
> 
> I've never seen someone try to make indentation work in that way with a
> backslash.  If I were you, I wouldn't mention it to your students, it might
> just confuse them further.
> 
> --Ned.
Thank for your advice me
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Indentation example?

2016-06-12 Thread ICT Ezy
On Sunday, June 12, 2016 at 9:36:16 PM UTC+5:30, Steven D'Aprano wrote:
> On Mon, 13 Jun 2016 01:10 am, ICT Ezy wrote:
> 
> > Pl explain with an example the following phase
> > "Indentation cannot be split over multiple physical lines using
> > backslashes; the whitespace up to the first backslash determines the
> > indentation" (in 2.1.8. Indentation of Tutorial.) I want to teach my
> > student that point using some examples. Pl help me any body?
> 
> 
> Good indentation:
> 
> def function():
> # four spaces per indent
> print("hello")
> print("goodbye")
> 
> 
> Bad indentation:
> 
> def function():
> # four spaces per indent
> print("hello")  # four spaces
>   \
>   print("goodbye")  # two spaces, then backslash, then two more
> 
> 
> The second example will be a SyntaxError.
> 
> 
> 
> -- 
> Steven

Thank you very much your example
-- 
https://mail.python.org/mailman/listinfo/python-list


Indentation example?

2016-06-12 Thread ICT Ezy
Pl explain with an example the following phase
"Indentation cannot be split over multiple physical lines using backslashes; 
the whitespace up to the first backslash determines the indentation" (in 2.1.8. 
Indentation of Tutorial.)
I want to teach my student that point using some examples.
Pl help me any body?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Operator precedence problem

2016-06-05 Thread ICT Ezy
On Sunday, June 5, 2016 at 10:49:49 PM UTC+5:30, Random832 wrote:
> On Sun, Jun 5, 2016, at 02:53, ICT Ezy wrote:
> > >>> 2 ** 3 ** 2 
> > Answer is 512
> > Why not 64?
> > Order is right-left or left-right?
> 
> You're mixing up order of evaluation with operator associativity. The **
> operator is right-to-left associative, this means x ** y ** z == x ** (y
> ** z). Evaluation is left to right, where it matters [i.e. if one or
> more of the elements here were an expression with side effects]: first x
> is evaluated, then tmp=y**z, then x**tmp. These are two entirely
> different concepts.

Thank you very much for your explanation
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Operator precedence problem

2016-06-05 Thread ICT Ezy
On Monday, June 6, 2016 at 5:18:21 AM UTC+5:30, Michael Torrie wrote:
> On 06/05/2016 10:05 AM, Uri Even-Chen wrote:
> > My suggestion: Never write expressions, such as  2 ** 3 ** 2 or even 2 * 4
> > + 5, without parentheses. Always add parentheses - 2 ** (3 ** 2) (or (2 **
> > 3) **2) or (2 * 4) + 5 (or 2 * (4 + 5)).
> 
> I can understand using parenthesis when operator precedence isn't
> working the way you want or expect, but I certainly would not recommend
> using it for basic arithmetic with multiplication, division, addition
> and subtraction. The rules of precedence for multiplication and division
> are well known and well-understood. If a language failed to implement
> them that would be a bug.  I think for the simple things extraneous
> parenthesis makes expressions more difficult for a human to parse
> because he will tend to second guess himself owing to extra parens.

Thank you very much for your explanation
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Operator precedence problem

2016-06-05 Thread ICT Ezy
On Sunday, June 5, 2016 at 9:36:20 PM UTC+5:30, Uri Even-Chen wrote:
> My suggestion: Never write expressions, such as  2 ** 3 ** 2 or even 2 * 4
> + 5, without parentheses. Always add parentheses - 2 ** (3 ** 2) (or (2 **
> 3) **2) or (2 * 4) + 5 (or 2 * (4 + 5)).
> 
> 
> *Uri Even-Chen*
> [image: photo] Phone: +972-54-3995700
> Email: u...@speedy.net
> Website: http://www.speedysoftware.com/uri/en/
> <http://www.facebook.com/urievenchen>  <http://plus.google.com/+urievenchen>
>   <http://www.linkedin.com/in/urievenchen>  <http://twitter.com/urievenchen>
> 
> On Sun, Jun 5, 2016 at 6:05 PM, ICT Ezy  wrote:
> 
> > On Sunday, June 5, 2016 at 1:06:21 PM UTC+5:30, Peter Otten wrote:
> > > ICT Ezy wrote:
> > >
> > > >>>> 2 ** 3 ** 2
> > > > Answer is 512
> > > > Why not 64?
> > > > Order is right-left or left-right?
> > >
> > > ** is a special case:
> > >
> > > """
> > > The power operator ** binds less tightly than an arithmetic or bitwise
> > unary
> > > operator on its right, that is, 2**-1 is 0.5.
> > > """
> > > https://docs.python.org/3.5/reference/expressions.html#id21
> > >
> > > Here's a little demo:
> > >
> > > $ cat arithdemo.py
> > > class A:
> > > def __init__(self, value):
> > > self.value = str(value)
> > > def __add__(self, other):
> > > return self._op(other, "+")
> > > def __pow__(self, other):
> > > return self._op(other, "**")
> > > def __repr__(self):
> > > return self.value
> > > def _op(self, other, op):
> > > return A("({} {} {})".format(self.value, op, other.value))
> > > $ python3 -i arithdemo.py
> > > >>> A(1) + A(2) + A(3)
> > > ((1 + 2) + 3)
> > > >>> A(1) ** A(2) ** A(3)
> > > (1 ** (2 ** 3))
> >
> > Thank you very much for your explanation
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >

Thank you very much for your explanation
-- 
https://mail.python.org/mailman/listinfo/python-list


how to work await x operator?

2016-06-05 Thread ICT Ezy
how to work await x Await expression operator? 
pl explain any one ...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Operator precedence problem

2016-06-05 Thread ICT Ezy
On Sunday, June 5, 2016 at 1:06:21 PM UTC+5:30, Peter Otten wrote:
> ICT Ezy wrote:
> 
> >>>> 2 ** 3 ** 2
> > Answer is 512
> > Why not 64?
> > Order is right-left or left-right?
> 
> ** is a special case:
> 
> """
> The power operator ** binds less tightly than an arithmetic or bitwise unary 
> operator on its right, that is, 2**-1 is 0.5.
> """
> https://docs.python.org/3.5/reference/expressions.html#id21
> 
> Here's a little demo:
> 
> $ cat arithdemo.py
> class A:
> def __init__(self, value):
> self.value = str(value)
> def __add__(self, other):
> return self._op(other, "+")
> def __pow__(self, other):
> return self._op(other, "**")
> def __repr__(self):
> return self.value
> def _op(self, other, op):
> return A("({} {} {})".format(self.value, op, other.value))
> $ python3 -i arithdemo.py 
> >>> A(1) + A(2) + A(3)
> ((1 + 2) + 3)
> >>> A(1) ** A(2) ** A(3)
> (1 ** (2 ** 3))

Thank you very much for your explanation 
-- 
https://mail.python.org/mailman/listinfo/python-list


Operator precedence problem

2016-06-04 Thread ICT Ezy
>>> 2 ** 3 ** 2 
Answer is 512
Why not 64?
Order is right-left or left-right?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to connect the MYSQL database to Python program?

2015-12-11 Thread ICT Ezy
On Friday, December 11, 2015 at 11:11:22 AM UTC-8, Igor Korot wrote:
> Hi,
> 
> On Fri, Dec 11, 2015 at 2:00 PM, ICT Ezy  wrote:
> > On Friday, December 11, 2015 at 10:52:49 AM UTC-8, larry@gmail.com 
> > wrote:
> >> On Fri, Dec 11, 2015 at 1:36 PM, ICT Ezy  wrote:
> >> > On Wednesday, December 9, 2015 at 9:58:02 AM UTC-8, Chris Angelico wrote:
> >> >> On Thu, Dec 10, 2015 at 4:51 AM, ICT Ezy  wrote:
> >> >> > Pl explain me how to connect the MYSQL database to Python program?
> >> >>
> >> >> You start by looking for a module that lets you do that. You can use
> >> >> your favourite web search engine, or go directly to PyPI.
> >> >>
> >> >> Then you learn how to use that module, including learning SQL if you
> >> >> don't already know it.
> >> >>
> >> >> ChrisA
> >> >
> >> > Now, I installed MYSQLDB and following code was done correctly.
> >> >
> >> > #!/usr/bin/python
> >> >
> >> > import MySQLdb
> >> >
> >> > # Open database connection
> >> > db = MySQLdb.connect("localhost","TESTDB")
> >>
> >> The connect should look like this:
> >>
> >> db= MySQLdb.connect(host, user, passwd, db)
> >>
> >> Or to be clearer:
> >>
> >> db= MySQLdb.connect(host="localhost", user="user", passwd="password",
> >> db="TESTDB")
> >
> > if there was error generated, i remove password and user
> >
> >>>> db= MySQLdb.connect(host="localhost", user="testuser", 
> >>>> passwd="test123",db="TESTDB")
> >
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > db= MySQLdb.connect(host="localhost", user="testuser", 
> > passwd="test123",db="TESTDB")
> >   File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in 
> > Connect
> > return Connection(*args, **kwargs)
> >   File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 193, in 
> > __init__
> > super(Connection, self).__init__(*args, **kwargs2)
> > OperationalError: (1045, "Acc\xe8s refus\xe9 pour l'utilisateur: 
> > 'testuser'@'@localhost' (mot de passe: OUI)")
> >>>>
> 
> Is the account testuser exist? Does it have a password "test123"?
> But more imp[ortantly - this does not have anything to do with Python.
> 
> Start by trying to connect from mySQL and try to execute some
> insert/update/delete statement.
> 
> Then when you succeed, start writing python code.
> 
> Thank you.
> 
> > pl check it
> > --
> > https://mail.python.org/mailman/listinfo/python-list

OK, I have done well now, misspelling occurred. Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to connect the MYSQL database to Python program?

2015-12-11 Thread ICT Ezy
On Friday, December 11, 2015 at 10:52:49 AM UTC-8, larry@gmail.com wrote:
> On Fri, Dec 11, 2015 at 1:36 PM, ICT Ezy  wrote:
> > On Wednesday, December 9, 2015 at 9:58:02 AM UTC-8, Chris Angelico wrote:
> >> On Thu, Dec 10, 2015 at 4:51 AM, ICT Ezy  wrote:
> >> > Pl explain me how to connect the MYSQL database to Python program?
> >>
> >> You start by looking for a module that lets you do that. You can use
> >> your favourite web search engine, or go directly to PyPI.
> >>
> >> Then you learn how to use that module, including learning SQL if you
> >> don't already know it.
> >>
> >> ChrisA
> >
> > Now, I installed MYSQLDB and following code was done correctly.
> >
> > #!/usr/bin/python
> >
> > import MySQLdb
> >
> > # Open database connection
> > db = MySQLdb.connect("localhost","TESTDB")
> 
> The connect should look like this:
> 
> db= MySQLdb.connect(host, user, passwd, db)
> 
> Or to be clearer:
> 
> db= MySQLdb.connect(host="localhost", user="user", passwd="password",
> db="TESTDB")

Ok Larry, I have success now, my names are misspelling. work well
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to connect the MYSQL database to Python program?

2015-12-11 Thread ICT Ezy
On Friday, December 11, 2015 at 10:52:49 AM UTC-8, larry@gmail.com wrote:
> On Fri, Dec 11, 2015 at 1:36 PM, ICT Ezy  wrote:
> > On Wednesday, December 9, 2015 at 9:58:02 AM UTC-8, Chris Angelico wrote:
> >> On Thu, Dec 10, 2015 at 4:51 AM, ICT Ezy  wrote:
> >> > Pl explain me how to connect the MYSQL database to Python program?
> >>
> >> You start by looking for a module that lets you do that. You can use
> >> your favourite web search engine, or go directly to PyPI.
> >>
> >> Then you learn how to use that module, including learning SQL if you
> >> don't already know it.
> >>
> >> ChrisA
> >
> > Now, I installed MYSQLDB and following code was done correctly.
> >
> > #!/usr/bin/python
> >
> > import MySQLdb
> >
> > # Open database connection
> > db = MySQLdb.connect("localhost","TESTDB")
> 
> The connect should look like this:
> 
> db= MySQLdb.connect(host, user, passwd, db)
> 
> Or to be clearer:
> 
> db= MySQLdb.connect(host="localhost", user="user", passwd="password",
> db="TESTDB")

if there was error generated, i remove password and user

>>> db= MySQLdb.connect(host="localhost", user="testuser", 
>>> passwd="test123",db="TESTDB")

Traceback (most recent call last):
  File "", line 1, in 
db= MySQLdb.connect(host="localhost", user="testuser", 
passwd="test123",db="TESTDB")
  File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
  File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 193, in 
__init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1045, "Acc\xe8s refus\xe9 pour l'utilisateur: 
'testuser'@'@localhost' (mot de passe: OUI)")
>>> 
pl check it
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python variable assigning problems...

2015-12-11 Thread ICT Ezy
On Friday, December 11, 2015 at 10:27:29 AM UTC-8, Jussi Piitulainen wrote:
> ICT Ezy writes:
> > On Friday, December 11, 2015 at 8:40:18 AM UTC-8, Ian wrote:
> >> 
> >> No, it actually happens left to right. "x = y = z = 0" means "assign
> >> 0 to x, then assign 0 to y, then assign 0 to z." It doesn't mean
> >> "assign 0 to z, then assign z to y, etc." This works:
> >> 
> >> >>> d = d['foo'] = {}
> >> >>> d
> >> {'foo': {...}}
> >> 
> >> This doesn't:
> >> 
> >> >>> del d
> >> >>> d['foo'] = d = {}
> >> Traceback (most recent call last):
> >>   File "", line 1, in 
> >> NameError: name 'd' is not defined
> >
> > Deat Ian,
> > Thank you very much your answer, but
> > above answer from Robin Koch and your answer is different. What's the
> > actually process here? I agree with Robin Koch, but your answer is
> > correct. Pl explain differences ?
> 
> Python language reference, at 7.2 Assignment statements, says this:
> 
> # An assignment statement evaluates the expression list (remember that
> # this can be a single expression or a comma-separated list, the latter
> # yielding a tuple) and assigns the single resulting object to each of
> # the target lists, from left to right.
> 
> To simplify a bit, it's talking about a statement of this form:
> 
>  target_list = target_list = target_list = expression_list
> 
> And it says what Ian said: the value of the expression is assigned to
> each target *from left to right*.
> 
> <https://docs.python.org/3/reference/simple_stmts.html#assignment-statements>
See also:

>>> x = [5, 6]
>>> x[i],x[j]
(5, 6)
>>> i,j=0,1
>>> x[i],x[j]=x[j],x[i]=2,3
>>> x[i],x[j]
(3, 2)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python variable assigning problems...

2015-12-11 Thread ICT Ezy
On Friday, December 11, 2015 at 10:27:29 AM UTC-8, Jussi Piitulainen wrote:
> ICT Ezy writes:
> > On Friday, December 11, 2015 at 8:40:18 AM UTC-8, Ian wrote:
> >> 
> >> No, it actually happens left to right. "x = y = z = 0" means "assign
> >> 0 to x, then assign 0 to y, then assign 0 to z." It doesn't mean
> >> "assign 0 to z, then assign z to y, etc." This works:
> >> 
> >> >>> d = d['foo'] = {}
> >> >>> d
> >> {'foo': {...}}
> >> 
> >> This doesn't:
> >> 
> >> >>> del d
> >> >>> d['foo'] = d = {}
> >> Traceback (most recent call last):
> >>   File "", line 1, in 
> >> NameError: name 'd' is not defined
> >
> > Deat Ian,
> > Thank you very much your answer, but
> > above answer from Robin Koch and your answer is different. What's the
> > actually process here? I agree with Robin Koch, but your answer is
> > correct. Pl explain differences ?
> 
> Python language reference, at 7.2 Assignment statements, says this:
> 
> # An assignment statement evaluates the expression list (remember that
> # this can be a single expression or a comma-separated list, the latter
> # yielding a tuple) and assigns the single resulting object to each of
> # the target lists, from left to right.
> 
> To simplify a bit, it's talking about a statement of this form:
> 
>  target_list = target_list = target_list = expression_list
> 
> And it says what Ian said: the value of the expression is assigned to
> each target *from left to right*.
> 
> <https://docs.python.org/3/reference/simple_stmts.html#assignment-statements>

Yes you correct!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to connect the MYSQL database to Python program?

2015-12-11 Thread ICT Ezy
On Wednesday, December 9, 2015 at 1:45:26 PM UTC-8, Mark Lawrence wrote:
> On 09/12/2015 17:51, ICT Ezy wrote:
> > Pl explain me how to connect the MYSQL database to Python program?
> >
> 
> Use a search engine.  Then run up an editor, write some code, run said 
> code.  If you then have problems state your OS, Python version and 
> provide us with the full traceback.
> 
> An alternative is to write a cheque for (say) GBP 1000 payable to the 
> Python Software Foundation and if you're lucky somebody will do your 
> homework for you.
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

I follow this link:
http://www.tutorialspoint.com/python/python_database_access.htm
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to connect the MYSQL database to Python program?

2015-12-11 Thread ICT Ezy
On Friday, December 11, 2015 at 10:36:33 AM UTC-8, ICT Ezy wrote:
> On Wednesday, December 9, 2015 at 9:58:02 AM UTC-8, Chris Angelico wrote:
> > On Thu, Dec 10, 2015 at 4:51 AM, ICT Ezy  wrote:
> > > Pl explain me how to connect the MYSQL database to Python program?
> > 
> > You start by looking for a module that lets you do that. You can use
> > your favourite web search engine, or go directly to PyPI.
> > 
> > Then you learn how to use that module, including learning SQL if you
> > don't already know it.
> > 
> > ChrisA
> 
> Now, I installed MYSQLDB and following code was done correctly. 
> 
> #!/usr/bin/python 
> 
> import MySQLdb 
> 
> # Open database connection 
> db = MySQLdb.connect("localhost","TESTDB") 
> 
> # prepare a cursor object using cursor() method 
> cursor = db.cursor() 
> 
> # execute SQL query using execute() method. 
> cursor.execute("SELECT VERSION()") 
> 
> # Fetch a single row using fetchone() method. 
> data = cursor.fetchone() 
> 
> print "Database version : %s " % data 
> 
> # disconnect from server 
> db.close() 
> 
> 
> Then done following SQL statements: 
> 
> #!/usr/bin/python 
> 
> import MySQLdb 
> 
> # Open database connection 
> db = MySQLdb.connect("localhost","TESTDB" ) 
> 
> # prepare a cursor object using cursor() method 
> cursor = db.cursor() 
> 
> 
> Then not correctly work following SQL statements: 
> 
> >>> import MySQLdb 
> >>> db = MySQLdb.connect("localhost","TESTDB" ) 
> >>> cursor = db.cursor() 
> >>> sql = """CREATE TABLE EMPLOYEE ( 
>  FIRST_NAME  CHAR(20) NOT NULL, 
>  LAST_NAME  CHAR(20), 
>  AGE INT, 
>  SEX CHAR(1), 
>  INCOME FLOAT )""" 
> >>> cursor.execute(sql) 
> 
> Traceback (most recent call last): 
>   File "", line 1, in  
> cursor.execute(sql) 
>   File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 205, in 
> execute 
> self.errorhandler(self, exc, value) 
>   File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in 
> defaulterrorhandler 
> raise errorclass, errorvalue 
> OperationalError: (1046, "Aucune base n'a \xe9t\xe9 s\xe9lectionn\xe9e") 
> >>> 
> 
> How to solve the problems. pl explain me

I follow this link:
http://www.tutorialspoint.com/python/python_database_access.htm
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to connect the MYSQL database to Python program?

2015-12-11 Thread ICT Ezy
On Wednesday, December 9, 2015 at 9:58:02 AM UTC-8, Chris Angelico wrote:
> On Thu, Dec 10, 2015 at 4:51 AM, ICT Ezy  wrote:
> > Pl explain me how to connect the MYSQL database to Python program?
> 
> You start by looking for a module that lets you do that. You can use
> your favourite web search engine, or go directly to PyPI.
> 
> Then you learn how to use that module, including learning SQL if you
> don't already know it.
> 
> ChrisA

Now, I installed MYSQLDB and following code was done correctly. 

#!/usr/bin/python 

import MySQLdb 

# Open database connection 
db = MySQLdb.connect("localhost","TESTDB") 

# prepare a cursor object using cursor() method 
cursor = db.cursor() 

# execute SQL query using execute() method. 
cursor.execute("SELECT VERSION()") 

# Fetch a single row using fetchone() method. 
data = cursor.fetchone() 

print "Database version : %s " % data 

# disconnect from server 
db.close() 


Then done following SQL statements: 

#!/usr/bin/python 

import MySQLdb 

# Open database connection 
db = MySQLdb.connect("localhost","TESTDB" ) 

# prepare a cursor object using cursor() method 
cursor = db.cursor() 


Then not correctly work following SQL statements: 

>>> import MySQLdb 
>>> db = MySQLdb.connect("localhost","TESTDB" ) 
>>> cursor = db.cursor() 
>>> sql = """CREATE TABLE EMPLOYEE ( 
 FIRST_NAME  CHAR(20) NOT NULL, 
 LAST_NAME  CHAR(20), 
 AGE INT, 
 SEX CHAR(1), 
 INCOME FLOAT )""" 
>>> cursor.execute(sql) 

Traceback (most recent call last): 
  File "", line 1, in  
cursor.execute(sql) 
  File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 205, in execute 
self.errorhandler(self, exc, value) 
  File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in 
defaulterrorhandler 
raise errorclass, errorvalue 
OperationalError: (1046, "Aucune base n'a \xe9t\xe9 s\xe9lectionn\xe9e") 
>>> 

How to solve the problems. pl explain me 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to connect the MYSQL database to Python program?

2015-12-11 Thread ICT Ezy
On Wednesday, December 9, 2015 at 1:45:26 PM UTC-8, Mark Lawrence wrote:
> On 09/12/2015 17:51, ICT Ezy wrote:
> > Pl explain me how to connect the MYSQL database to Python program?
> >
> 
> Use a search engine.  Then run up an editor, write some code, run said 
> code.  If you then have problems state your OS, Python version and 
> provide us with the full traceback.
> 
> An alternative is to write a cheque for (say) GBP 1000 payable to the 
> Python Software Foundation and if you're lucky somebody will do your 
> homework for you.
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

Now, I installed MYSQLDB and following code was done correctly.

#!/usr/bin/python

import MySQLdb

# Open database connection
db = MySQLdb.connect("localhost","TESTDB")

# prepare a cursor object using cursor() method
cursor = db.cursor()

# execute SQL query using execute() method.
cursor.execute("SELECT VERSION()")

# Fetch a single row using fetchone() method.
data = cursor.fetchone()

print "Database version : %s " % data

# disconnect from server
db.close()


Then done following SQL statements:

#!/usr/bin/python

import MySQLdb

# Open database connection
db = MySQLdb.connect("localhost","TESTDB" )

# prepare a cursor object using cursor() method
cursor = db.cursor()


Then not correctly work following SQL statements:

>>> import MySQLdb
>>> db = MySQLdb.connect("localhost","TESTDB" )
>>> cursor = db.cursor()
>>> sql = """CREATE TABLE EMPLOYEE (
 FIRST_NAME  CHAR(20) NOT NULL,
 LAST_NAME  CHAR(20),
 AGE INT,
 SEX CHAR(1),
 INCOME FLOAT )"""
>>> cursor.execute(sql)

Traceback (most recent call last):
  File "", line 1, in 
cursor.execute(sql)
  File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
  File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in 
defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (1046, "Aucune base n'a \xe9t\xe9 s\xe9lectionn\xe9e")
>>> 

How to solve the problems. pl explain me


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python variable assigning problems...

2015-12-11 Thread ICT Ezy
On Friday, December 11, 2015 at 10:20:30 AM UTC-8, Michael Torrie wrote:
> On 12/11/2015 11:05 AM, ICT Ezy wrote:
> > Deat Ian, Thank you very much your answer, but above answer from
> > Robin Koch and your answer is different. What's the actually process
> > here? I agree with Robin Koch, but your answer is correct. Pl explain
> > differences ?
> 
> If you go re-read the answers, you'll find Ian has explained why Robin
> was incorrect, and Robin acknowledged he got it wrong.

OK. I got it!!!
Yeh, Your discussion is very good, really I understood correct process, Thank 
you very much all of you!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python variable assigning problems...

2015-12-11 Thread ICT Ezy
On Friday, December 11, 2015 at 9:53:10 AM UTC-8, Robin Koch wrote:
> Am 11.12.2015 um 17:39 schrieb Ian Kelly:
> > On Fri, Dec 11, 2015 at 9:24 AM, Robin Koch  wrote:
> >> Assigning goes from right to left:
> >>
> >> x,y=y,x=2,3
> >>
> >> <=>
> >>
> >> y, x = 2, 3
> >> x, y = y, x
> >>
> >> Otherwise the assignment x, y = y, x would not make any sense, since x and 
> >> y
> >> haven't any values yet.
> >>
> >> And the execution from right to left is also a good choice, because one
> >> would like to do something like:
> >>
> >> x = y = z = 0
> >>
> >> Again, assigning from left to right woud lead to errors.
> >
> > No, it actually happens left to right. "x = y = z = 0" means "assign 0
> > to x, then assign 0 to y, then assign 0 to z." It doesn't mean "assign
> > 0 to z, then assign z to y, etc."
> 
> Oh. Ok, then, thanks for this correction.
> Although it's consequent to use left-to-right precedence it's a little 
> counter intuitive in the sense that the rightmost and leftmost objects 
> interact. Especially with a background in mathematics. :-)
> 
>  > This works:
> >
>  d = d['foo'] = {}
>  d
> > {'foo': {...}}
> >
> > This doesn't:
> >
>  del d
>  d['foo'] = d = {}
> > Traceback (most recent call last):
> >File "", line 1, in 
> > NameError: name 'd' is not defined
> 
> Good to know! Thank you.
> 
> -- 
> Robin Koch

Yeh, Your discussion is very good, really I understood correct process, Thank 
you very much all of you!  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python variable assigning problems...

2015-12-11 Thread ICT Ezy
On Friday, December 11, 2015 at 8:40:18 AM UTC-8, Ian wrote:
> On Fri, Dec 11, 2015 at 9:24 AM, Robin Koch  wrote:
> > Assigning goes from right to left:
> >
> > x,y=y,x=2,3
> >
> > <=>
> >
> > y, x = 2, 3
> > x, y = y, x
> >
> > Otherwise the assignment x, y = y, x would not make any sense, since x and y
> > haven't any values yet.
> >
> > And the execution from right to left is also a good choice, because one
> > would like to do something like:
> >
> > x = y = z = 0
> >
> > Again, assigning from left to right woud lead to errors.
> 
> No, it actually happens left to right. "x = y = z = 0" means "assign 0
> to x, then assign 0 to y, then assign 0 to z." It doesn't mean "assign
> 0 to z, then assign z to y, etc." This works:
> 
> >>> d = d['foo'] = {}
> >>> d
> {'foo': {...}}
> 
> This doesn't:
> 
> >>> del d
> >>> d['foo'] = d = {}
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'd' is not defined

Deat Ian,
Thank you very much your answer, but
above answer from Robin Koch and your answer is different. What's the actually 
process here? I agree with Robin Koch, but your answer is correct. Pl explain 
differences ?


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python variable assigning problems...

2015-12-11 Thread ICT Ezy
On Friday, December 11, 2015 at 8:24:45 AM UTC-8, Robin Koch wrote:
> Am 11.12.2015 um 17:10 schrieb ICT Ezy:
> > Dear All,
> > Very Sorry for the my mistake here. I code here with mu question ...
> >
> > My Question:
> >
> > A,B=C,D=10,11
> > print(A,B,C,D)
> > #(10,11,10,11) --> This is OK!
> >
> > a=1; b=2
> > a,b=b,a
> > print(a,b)
> > # (1,2) --> This is OK!
> >
> > x,y=y,x=2,3
> > print(x,y)
> > # (3,2) --> Question: How to explain it?
> > # Not understand this process. Pl explain ...
> 
> What else would you expect?
> 
> Assigning goes from right to left:
> 
> x,y=y,x=2,3
> 
> <=>
> 
> y, x = 2, 3
> x, y = y, x
> 
> Otherwise the assignment x, y = y, x would not make any sense, since x 
> and y haven't any values yet.
> 
> And the execution from right to left is also a good choice, because one 
> would like to do something like:
> 
> x = y = z = 0
> 
> Again, assigning from left to right woud lead to errors.
> 
> -- 
> Robin Koch

Thank you very much your answer, I had not known assignment id Right2Left 
before. I done it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python variable assigning problems...

2015-12-11 Thread ICT Ezy
Dear All,
Very Sorry for the my mistake here. I code here with mu question ...

My Question:

A,B=C,D=10,11
print(A,B,C,D)
#(10,11,10,11) --> This is OK!

a=1; b=2
a,b=b,a
print(a,b)
# (1,2) --> This is OK!

x,y=y,x=2,3
print(x,y)
# (3,2) --> Question: How to explain it?
# Not understand this process. Pl explain ...
-- 
https://mail.python.org/mailman/listinfo/python-list


How to connect the MYSQL database to Python program?

2015-12-09 Thread ICT Ezy
Pl explain me how to connect the MYSQL database to Python program?
-- 
https://mail.python.org/mailman/listinfo/python-list


Python variable assigning problems...

2015-12-09 Thread ICT Ezy
Pl refer question which attached image here:

link: https://drive.google.com/open?id=0B5L920jMv7T0dFNKQTJ2UUdudW8
-- 
https://mail.python.org/mailman/listinfo/python-list