Re: back with more issues
import random
class player():
hp = 10
attack = random.randint(0,5)
class monster():
hp = 10
attack = random.randint(0,4)
def battle():
print ("a wild mosnter appered!")
print ("would you like to battle?")
answer = input()
if answer == ("yes"):
while monster.hp >=0:
print ("you do", player.attack, "damage")
monster.hp -= player.attack
print (monster.hp)
elif answer == ("no"):
print ("you run away")
else:
print("you stand there")
battle()
Hello! just wanted to show you guys how its coming together, im starting to
understand it abit more (hopefully it's right) at the moment it seems to only
roll the attack once and uses that value but that's another issue all together
that i bother you with (yet anyway).
thanks again guys you are awesome
--
http://mail.python.org/mailman/listinfo/python-list
[ANN] New article:
Dear all The following article had been peer-reviewed and accepted by The Python Papers. Title: A Python Module for FITS Files with full C Level Programming Functionality Abstract: A Python module for manipulating files in the FITS format is described. The module was constructed using the capabilites of ctypes to dynamically create foreign function interfaces from a C library. Here this was used to import the CFITSIO library into Python. I describe how this module can be used to call the functions from the C library in their near native form, and how one to manipulate FITS files in a style that Python programmers are accustomed. The ctypes and ctypeslib modules allows one to import all routines and data structures from the C library and avoids the need to manually write language bindings for each routine. Moreover, these modules allow the Python programmer to enjoy the full functionality of the the underlying C library. http://ojs.pythonpapers.org/index.php/tpp/article/view/250 Maurice Ling Co-EIC, The Python Papers -- http://mail.python.org/mailman/listinfo/python-list
Re: back with more issues
Kris Mesenbrink wrote: > darn i was hoping i could put off learning classes for a bit, but it seems > that is not the case. i have tested it a bit and it seems to be working > correctly now. > > > import random > > class player(): > hp = 10 > speed = 5 > attack = random.randint(0,5) > > print (player.attack) > > +++ > > i know it's not nearly as complicated as your examples but it seems to work. > the self part of it always eluded me and continues to do so. and just so you > know im learning through codecademy.com , it's based on python 2.7 and im > trying to code in 3.3. but thanks for your help again and classes are > starting (i think) to make some sort of sense.i'll have to reread both > replies over and over again but it looks like a lot of useful info is there. > but is the example i posted sorta right? i know i left the self part out but > i think im on the right track. The "complication" was there for good reason. If you are sure you'll never have more than one player, this could work. i don't see the advantage over (ugh) global variables, however. But what happens when you have four monsters instead of one? A class provides you a way to store data for each instance, not just for the class as a whole. And the self convention is kind of analogous to the English "myself." If you're inside an ordinary method, you refer to yourself as "self." By the way, by convention, class names are capitalized. That's why i called it Player. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Calling Python macro from ctypes
Is it possible to call a Python macro from ctypes? For example, Python 3.3 introduces some new macros for querying the internal representation of strings: http://www.python.org/dev/peps/pep-0393/#new-api So I try this in 3.3: py> import ctypes py> ctypes.pythonapi.PyUnicode_MAX_CHAR_VALUE Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.3/ctypes/__init__.py", line 366, in __getattr__ func = self.__getitem__(name) File "/usr/local/lib/python3.3/ctypes/__init__.py", line 371, in __getitem__ func = self._FuncPtr((name_or_ordinal, self)) AttributeError: python3.3: undefined symbol: PyUnicode_MAX_CHAR_VALUE -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling Python macro from ctypes
Steven D'Aprano wrote:
> Is it possible to call a Python macro from ctypes? For example, Python
> 3.3 introduces some new macros for querying the internal representation
> of strings:
>
> http://www.python.org/dev/peps/pep-0393/#new-api
>
>
> So I try this in 3.3:
>
> py> import ctypes
> py> ctypes.pythonapi.PyUnicode_MAX_CHAR_VALUE
> Traceback (most recent call last):
> File "", line 1, in
> File "/usr/local/lib/python3.3/ctypes/__init__.py", line 366, in
> __getattr__
> func = self.__getitem__(name)
> File "/usr/local/lib/python3.3/ctypes/__init__.py", line 371, in
> __getitem__
> func = self._FuncPtr((name_or_ordinal, self))
> AttributeError: python3.3: undefined symbol: PyUnicode_MAX_CHAR_VALUE
That's not possible. It may look like a function, but a preprocessor
replaces the C macro in the C source before compilation. An example of very
bad usage of macros, just to drive the point home:
$ cat macro.c
#define IF(expr) if (expr) {
#define ENDIF ;}
main()
{
IF(1>0)
printf("It worked\n")
ENDIF
}
And here's what the compiler sees:
$ gcc -E -P macro.c
main()
{
if (1>0) {
printf("It worked\n")
;}
}
--
http://mail.python.org/mailman/listinfo/python-list
Re: Am I not seeing the Error?
On 08/10/2013 10:47 PM, Chris Angelico wrote: On Sun, Aug 11, 2013 at 3:43 AM, Roy Smith wrote: In article , Chris Angelico wrote: When you get a syntax error you can't understand, look at the previous line of code. Perhaps something there is incomplete; maybe you have mismatched parentheses, so this line is considered to be part of the same expression. Next thing to do is split it into more lines. Why is all that in a single line? Also, try reformatting the code in a tool like emacs or eclipse which does syntax coloring and auto indenting. Often, if you're missing some piece of punctuation, it will become obvious when your tool tries to indent things in some unexpected way. Or suddenly starts coloring all of your program text as if it were a string literal :-) Agreed. Though I've had some odd issues with SciTE in that way; I think its Python handling may have bugs in it here and there. But 95% of the time it's helpful. ChrisA Thanks everyone. Unfortunately, I have not found the problem yet. I use the Geany IDE which has syntax highlighting, but nothing wrong is seen. None of the suggestions helped. The lines before this one set variables. The lines further up "appear" fine. I will keep looking. If I ever figure it out, I will share with all of you. As for the code being one line, my style of coding is very different from others. I try to keep similar or related tasks on one line. Programming like that is called trolling. A programmer that uses trolling is called a troll. A troll can also refer to such a line of code itself. My scripts contain a lot of trolls. It is easier for me to read trolls than "typical" coding styles. (Yes, I am a weird troll (^u^)) Mahalo, [email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I not seeing the Error?
On Mon, Aug 12, 2013 at 7:33 AM, Devyn Collier Johnson wrote: > > On 08/10/2013 10:47 PM, Chris Angelico wrote: >> >> On Sun, Aug 11, 2013 at 3:43 AM, Roy Smith wrote: >>> >>> In article , >>> Chris Angelico wrote: >>> When you get a syntax error you can't understand, look at the previous line of code. Perhaps something there is incomplete; maybe you have mismatched parentheses, so this line is considered to be part of the same expression. Next thing to do is split it into more lines. Why is all that in a single line? >>> >>> Also, try reformatting the code in a tool like emacs or eclipse which >>> does syntax coloring and auto indenting. Often, if you're missing some >>> piece of punctuation, it will become obvious when your tool tries to >>> indent things in some unexpected way. Or suddenly starts coloring all >>> of your program text as if it were a string literal :-) >> >> Agreed. Though I've had some odd issues with SciTE in that way; I >> think its Python handling may have bugs in it here and there. But 95% >> of the time it's helpful. >> >> ChrisA > > > Thanks everyone. Unfortunately, I have not found the problem yet. I use the > Geany IDE which has syntax highlighting, but nothing wrong is seen. None of > the suggestions helped. The lines before this one set variables. The lines > further up "appear" fine. I will keep looking. If I ever figure it out, I > will share with all of you. > > As for the code being one line, my style of coding is very different from > others. I try to keep similar or related tasks on one line. Programming like > that is called trolling. A programmer that uses trolling is called a troll. > A troll can also refer to such a line of code itself. My scripts contain a > lot of trolls. It is easier for me to read trolls than "typical" coding > styles. Obviously not, since you can't find the syntax error. If you replace each semicolon in that line with a newline, the syntax error will be immediately obvious. I'll even give you a hint: it's on the third line. -- Zach -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I not seeing the Error?
On 8/12/13 8:33 AM, Devyn Collier Johnson wrote:
On 08/10/2013 10:47 PM, Chris Angelico wrote:
On Sun, Aug 11, 2013 at 3:43 AM, Roy Smith wrote:
In article ,
Chris Angelico wrote:
When you get a syntax error you can't understand, look at the previous
line of code. Perhaps something there is incomplete; maybe you have
mismatched parentheses, so this line is considered to be part of the
same expression.
Next thing to do is split it into more lines. Why is all that in a
single
line?
Also, try reformatting the code in a tool like emacs or eclipse which
does syntax coloring and auto indenting. Often, if you're missing some
piece of punctuation, it will become obvious when your tool tries to
indent things in some unexpected way. Or suddenly starts coloring all
of your program text as if it were a string literal :-)
Agreed. Though I've had some odd issues with SciTE in that way; I
think its Python handling may have bugs in it here and there. But 95%
of the time it's helpful.
ChrisA
Thanks everyone. Unfortunately, I have not found the problem yet. I
use the Geany IDE which has syntax highlighting, but nothing wrong is
seen. None of the suggestions helped. The lines before this one set
variables. The lines further up "appear" fine. I will keep looking. If
I ever figure it out, I will share with all of you.
As Terry Reedy pointed out, you have semicolons separating arguments in
a function call. This is your line of code:
JOB_WRITEURGFILES =
multiprocessing.Process(write2file('./mem/ENGINE_PID', ENGINEPID);
write2file(SENTEMPPATH, ''); write2file(INPUTMEM, ''));
JOB_WRITEURGFILES.start()
Replacing names with shorter ones to see the structure, it's like this:
J = m.P( w('', E); w(S, ''); w(I, '') ); J.s()
You have three semicolons in that line. Two are inside a call, though
I'm not sure that's what you intended. One is separating statements.
You might be a little too attached to your "more readable" style.
Putting things on different lines really does help you see what is going on.
--Ned.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Am I not seeing the Error?
On 08/12/2013 09:20 AM, Zachary Ware wrote: On Mon, Aug 12, 2013 at 7:33 AM, Devyn Collier Johnson wrote: On 08/10/2013 10:47 PM, Chris Angelico wrote: On Sun, Aug 11, 2013 at 3:43 AM, Roy Smith wrote: In article , Chris Angelico wrote: When you get a syntax error you can't understand, look at the previous line of code. Perhaps something there is incomplete; maybe you have mismatched parentheses, so this line is considered to be part of the same expression. Next thing to do is split it into more lines. Why is all that in a single line? Also, try reformatting the code in a tool like emacs or eclipse which does syntax coloring and auto indenting. Often, if you're missing some piece of punctuation, it will become obvious when your tool tries to indent things in some unexpected way. Or suddenly starts coloring all of your program text as if it were a string literal :-) Agreed. Though I've had some odd issues with SciTE in that way; I think its Python handling may have bugs in it here and there. But 95% of the time it's helpful. ChrisA Thanks everyone. Unfortunately, I have not found the problem yet. I use the Geany IDE which has syntax highlighting, but nothing wrong is seen. None of the suggestions helped. The lines before this one set variables. The lines further up "appear" fine. I will keep looking. If I ever figure it out, I will share with all of you. As for the code being one line, my style of coding is very different from others. I try to keep similar or related tasks on one line. Programming like that is called trolling. A programmer that uses trolling is called a troll. A troll can also refer to such a line of code itself. My scripts contain a lot of trolls. It is easier for me to read trolls than "typical" coding styles. Obviously not, since you can't find the syntax error. If you replace each semicolon in that line with a newline, the syntax error will be immediately obvious. I'll even give you a hint: it's on the third line. Zachary, are you, Ned, and Terry trying to say the syntax should be job = multiprocessing.Process(func1(), func2()) not job = multiprocessing.Process(func1(); func2()) DCJ -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I not seeing the Error?
In Devyn Collier Johnson
writes:
> I am checking my 1292-line script for syntax errors. I ran the following
> commands in a terminal to check for errors, but I do not see the error.
>File "./beta_engine", line 344
> JOB_WRITEURGFILES =
> multiprocessing.Process(write2file('./mem/ENGINE_PID', ENGINEPID);
You have too many ('s this line.
> write2file(SENTEMPPATH, ''); write2file(INPUTMEM, ''));
And too many )'s on this one.
--
John Gordon A is for Amy, who fell down the stairs
[email protected] B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
http://mail.python.org/mailman/listinfo/python-list
Re: back with more issues
On 12/08/2013 06:54, Dave Angel wrote: [...] This function makes no sense to me. A function should have three well-defined pieces: what are its parameters, what does it do, what are its side-effects, and what does it return. No! A function should have *four* well-defined pieces: what are its parameters, what does it do, what are its side-effects, what does it return, and an almost fanatical devotion to the Pope [etc.] -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I not seeing the Error?
On Mon, Aug 12, 2013 at 9:04 AM, Devyn Collier Johnson
wrote:
>
> Zachary, are you, Ned, and Terry trying to say the syntax should be
>
> job = multiprocessing.Process(func1(), func2())
>
> not
>
> job = multiprocessing.Process(func1(); func2())
>
Basically, yes. The first option there is equivalent to this:
func_returns = (func1(), func2())
job = multiprocessing.Process(*func_returns)
The second option is equivalent to this:
job = multiprocessing.Process(func1()
func2())
...which is actually several different syntax errors, depending on how
you look at it. Semi-colon is only ever used in Python as a
substitute for \n-plus-some-spaces. And, since in your original
example, your semi-colons are inside parenthesis, they really have no
effect at all due to implicit line continuation within parens. So
your original line:
JOB_WRITEURGFILES =
multiprocessing.Process(write2file('./mem/ENGINE_PID', ENGINEPID);
write2file(SENTEMPPATH, ''); write2file(INPUTMEM, ''));
JOB_WRITEURGFILES.start()
is really:
JOB_WRITEURGFILES =
multiprocessing.Process(write2file('./mem/ENGINE_PID', ENGINEPID)
write2file(SENTEMPPATH, '') write2file(INPUTMEM, ''))
JOB_WRITEURGFILES.start()
It should be obvious now that the syntax error comes from not
separating the arguments to Process.
Trying to read between the lines a little here, I don't think you have
quite figured out how multiprocessing.Process works; that first option
above will only work if func1 returns None and func2 returns a
callable object and the second has no hope. I think this is more
along the lines of what you're really after:
def process_func():
func1()
func2()
if __name__ == '__main__':
job = multiprocessing.Process(target=process_func) # note: no
() after process_func!
job.start()
I'd suggest giving the multiprocessing.Process docs [0] a good
read-through. Keep in mind that Process is just a type like any other
(str, int, list, etc.), and calling its constructor is subject to the
same rules as any other function call.
--
Zach
[0] http://docs.python.org/3/library/multiprocessing#the-process-class
--
http://mail.python.org/mailman/listinfo/python-list
Re: Am I not seeing the Error?
On Mon, Aug 12, 2013 at 10:37 AM, Zachary Ware wrote: > [snip my last reply with a few code samples] My apologies for Gmail's mangling of my samples. Any code that is not indented should be on the previous line. -- Zach -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I not seeing the Error?
I can't quite sort out the multiple quoting levels, but somebody said: >>> Programming like that is called trolling. A programmer that uses >>> trolling is called a troll. A troll can also refer to such a line >>> of code itself. My scripts contain a lot of trolls. It is easier >>> for me to read trolls than "typical" coding styles. Please tell me this is all just an elaborate joke. -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I not seeing the Error?
On Mon, Aug 12, 2013 at 11:47 AM, Roy Smith wrote: > I can't quite sort out the multiple quoting levels, but somebody said: > Programming like that is called trolling. A programmer that uses trolling is called a troll. A troll can also refer to such a line of code itself. My scripts contain a lot of trolls. It is easier for me to read trolls than "typical" coding styles. > > Please tell me this is all just an elaborate joke. I was thinking something similar Roy. Devyn, you may think you code differently, but you don't. You have a half of dozen people trying to show you how your style causes confusion between what you think you are writing and what you actually coded. There is plenty of room in coding for personal expression, but what you call 'trolling' is not that. If you like semicolons, use another language that needs them. I think you think it is some version of premature optimization. Since you are a novice at the language, stick with the standards, and learn to embrace them. Ultimately standard coding styles has nothing to do with code optimization. It has to do with readability. Although this is a small example, you can see that if several people get involved debugging it, the first thing that gets in the way is your non-standard coding style. If you want to code alone your whole life, do as you like. But the time spent reading and fixing code in the lifetime of any useful software system is greater than the time spent creating the original code. > -- > http://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling Python macro from ctypes
Peter Otten wrote:
> Steven D'Aprano wrote:
>
>> Is it possible to call a Python macro from ctypes? For example, Python
>> 3.3 introduces some new macros for querying the internal representation
>> of strings:
>>
>> http://www.python.org/dev/peps/pep-0393/#new-api
>>
>>
>> So I try this in 3.3:
>>
>> py> import ctypes
>> py> ctypes.pythonapi.PyUnicode_MAX_CHAR_VALUE
>> Traceback (most recent call last):
>> File "", line 1, in
>> File "/usr/local/lib/python3.3/ctypes/__init__.py", line 366, in
>> __getattr__
>> func = self.__getitem__(name)
>> File "/usr/local/lib/python3.3/ctypes/__init__.py", line 371, in
>> __getitem__
>> func = self._FuncPtr((name_or_ordinal, self))
>> AttributeError: python3.3: undefined symbol: PyUnicode_MAX_CHAR_VALUE
>
> That's not possible. It may look like a function, but a preprocessor
> replaces the C macro in the C source before compilation. An example of very
> bad usage of macros, just to drive the point home:
>
> $ cat macro.c
> #define IF(expr) if (expr) {
> #define ENDIF ;}
>
> main()
> {
> IF(1>0)
> printf("It worked\n")
> ENDIF
> }
>
> And here's what the compiler sees:
>
> $ gcc -E -P macro.c
>
>
>
> main()
> {
> if (1>0) {
> printf("It worked\n")
> ;}
> }
>
To elaborate a bit more, Python can only see those symbols that are put
into the shared library They can be functions, and they can be
"values," but they don't include macros, which are processed by the
preprocessor, before the real C compiler even starts. C Macros are
actually text-substitution rules. They can look like functions, but
those functions do not end up in the shared library.
In Windows, you can use dumpbin to examine a DLL and see what symbols it
exports. I don't remember the syntax; it's been years.
I assume there's a similar tool for Linux to examine a shared library
(typically an .so file). Perhaps "readelf" and/or "nm" is such a tool,
but I don't really know. Although I've been using Python and C++ in
Linux in recent years, I haven't used them together, and neither have
I had to examine a shared library.
The following link looks interesting, but I haven't read it yet.
http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list
Re: Am I not seeing the Error?
On Mon, Aug 12, 2013 at 5:56 PM, Joel Goldstick wrote: > If you like semicolons, use another language that needs them. > I think you think it is some version of premature optimization. Since > you are a novice at the language, stick with the standards, and learn > to embrace them. I'm a C programmer who really likes his semicolons, and I often write long lines. But I still was right up there early on saying "split this line". It definitely wants to be split. And when *I* say that, it must be pretty notably splittable. :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
SSL issues in Python stdlib and 3rd party code
-BEGIN PGP SIGNED MESSAGE- Hash: SHA512 Hello, (re-post from the Python developer list) last week Ryan Sleevi of the Google Chrome Security Team has informed us about about two issues in Python's SSL module. I already new about the cause of the first bug and suspected that our SSL module suffers from the second bug but I was unable to prove it. Both issues are security issues but their impact is limited if you trust only trustworthy root certification authorities. Any decent root CA would should not sign a malicious cert with NULL bytes in a subjectAltName dNSName field or with wildcards like *.*.com. By the way if you are using the cacert.pem from curl, please update your bundle ASAP. I have found a bug in its Mozilla certdata parser, too. bug #1: ssl.match_hostname() wildcard matching - -- ssl.match_hostname() doesn't implement RFC 6125 wildcard matching rules. Affected versions: - - Python 3.2 (< 3.2.5) - - Python 3.3 (< 3.3.3) - - Python 3.4a1 - - requests < 1.2.3 https://pypi.python.org/pypi/requests - - backports.ssl_match_hostname (<3.2a3) https://pypi.python.org/pypi/backports.ssl_match_hostname/ - - urllib3 < 1.6 https://github.com/shazow/urllib3 Bug reports: http://bugs.python.org/issue17997 https://github.com/kennethreitz/requests/issues/1528 https://bitbucket.org/brandon/backports.ssl_match_hostname/issue/2/match_hostname-doesnt-implement-rfc-6125 Patch: http://bugs.python.org/issue17997 has a preliminary patch. The handling of IDN A-labels is still a bit controversial, though. bug #2 failure to handle NULL bytes in subjectAltName - - It's basically the same issue as CVE-2013-4073. Python uses GENERAL_NAME_print() to turn a GERNAL_NAME entry into a C string. But GENERAL_NAME_print() doesn't handle embedded NULL bytes in ASN1_STRINGs correctly. You can read more about the issue at http://www.ruby-lang.org/en/news/2013/06/27/hostname-check-bypassing-vulnerability-in-openssl-client-cve-2013-4073/ Affected versions: - - Python 2.6 (< 2.6.8) - - Python 2.7 (< 2.7.5) - - Python 3.2 (< 3.2.5) - - Python 3.3 (< 3.3.3) - - Python 3.4a1 - - PyOpenSSL < 0.13 https://pypi.python.org/pypi/pyOpenSSL - - eGenix.com pyOpenSSL Distribution with PyOpenSSL < 0.13 https://pypi.python.org/pypi/M2Crypto - - M2Crypto < 0.21.1 http://www.egenix.com/products/python/pyOpenSSL/ Bug report: http://bugs.python.org/issue18709 Patches: http://bugs.python.org/issue18709 has patches for 2.7, 3.3 and default https://code.launchpad.net/~heimes/pyopenssl/pyopenssl/+merge/179673 Jean-Paul Calderone is going to release 0.13.1 soonish. It's going to contain just my fix for the issue. Marc-Andre Lemburg will build a new version of eGenix.com pyOpenSSL Distribution shortly after. I'm not going to work on a patch for M2Crypto as I don't understand SWIG. I have contacted Heikki Toivonen for M2Crypto but haven't heard back from him yet. related issue: Mozilla's certdata.txt and CKT_NSS_MUST_VERIFY_TRUST - --- Recently I found bugs in curl's mk-ca-bundle.pl script, its cacert.pem and in the CA bundle of eGenix.com pyOpenSSL Distribution. Both failed to handle a new option in Mozilla's certdata.txt database correctly. As a consequence the root CA bundles contained additionally and untrustworthy root certificates. I'm not sure about the severity of the issue. Curl has already fixed its script week ago. Marc-Andre Lemburg is going to release a new distribution very soon. https://github.com/bagder/curl/commit/51f0b798fa http://curl.haxx.se/docs/caextract.html Background information: https://www.imperialviolet.org/2012/01/30/mozillaroots.html http://lists.debian.org/debian-release/2012/11/msg00411.html http://p11-glue.freedesktop.org/doc/storing-trust-policy/storing-trust-existing.html I like to thank Ryan Sleevi (Google), Chris Palmer (Google), Marc-Andre Lemburg (eGenix.com, Python core dev), Jean-Paul Calderone (PyOpenSSL), Antoine Pitrou (Python core dev), Daniel Stenberg (curl), Günter Knauf (curl) and everybody else who was involved in reporting and fixing these issues. Regards, Christian -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with undefined - http://www.enigmail.net/ iQIcBAEBCgAGBQJSCRlqAAoJEMeIxMHUVQ1Fmq0QAJoKFK3V1iiB+3hhvPfJGnLn pSMzm9CpIineF7KRSI50GYls7gwO5Nggqol2V7qcEzpRCPFxkV9E2t75Q8OnBW0+ ZHOoTjpLD086HeQ4oIcGN6byQcHwIbIVh74hRFu7ZW4jqLQwvyPrGwRonRv5a6nG 0tRqp/Swqyqvo4KTpxV26MdZNwD+c+ASO0gmQzW6SURS5/gUKv0fDWjUwqC9COdZ Xz9wsLZaul+e6ewH7N5c7EWRXEs8l8cVk68Jw+/Jshct4kfWUnnw67qPjcoDgHLI tZzjVy7aCp2V9vjKvAcM2OUz0Q5h1rIFc5Roh5yH8OxuOn+Zn6zs3M6DKHJI9n12 JTTyi4yBu5hBRFqOWYSicytQpHAT604zpaGY7g4Hd0J98tG0kuT0BC7tozdi+MUW eXuBML7uYOBlI/VCIv/baZAaRj1txPZl5Vf9a75N2lb2seavUJDu8HqOzh+zxSTC 9agPuGAJOrU5mljkBKCCVy6/4njktjOBDmQsf9OHZ0/FolBjQuiJyXp4hLMQMqzY /ji4HtLF7Er
Re: connection change
On Sun, Aug 11, 2013 at 7:50 PM, Inna Belakhova wrote: > Hi, > > I don't know much about Python code. Where is the connection made, eg > config file - where can I find it? > > Our SQLITe database is currently 9GB and we have a table that contains > 7GB of BLOB type. I think the table cannot handle any more insert of > BLOB hence I want to change it to SQL database - which has no > restriction on database size. > > Any suggestions? use google: "python mssql" > > Cheers, > Inna > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: back with more issues
On Mon, Aug 12, 2013, at 10:56, Rotwang wrote: > No! A function should have *four* well-defined pieces: what are its > parameters, what does it do, what are its side-effects, what does it > return, and an almost fanatical devotion to the Pope [etc.] To be fair, I can't think of what "what does it do" includes other than the side-effects and the return. -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I not seeing the Error?
On 08/12/2013 12:56 PM, Joel Goldstick wrote: On Mon, Aug 12, 2013 at 11:47 AM, Roy Smith wrote: I can't quite sort out the multiple quoting levels, but somebody said: Programming like that is called trolling. A programmer that uses trolling is called a troll. A troll can also refer to such a line of code itself. My scripts contain a lot of trolls. It is easier for me to read trolls than "typical" coding styles. Please tell me this is all just an elaborate joke. I was thinking something similar Roy. Devyn, you may think you code differently, but you don't. You have a half of dozen people trying to show you how your style causes confusion between what you think you are writing and what you actually coded. There is plenty of room in coding for personal expression, but what you call 'trolling' is not that. If you like semicolons, use another language that needs them. I think you think it is some version of premature optimization. Since you are a novice at the language, stick with the standards, and learn to embrace them. Ultimately standard coding styles has nothing to do with code optimization. It has to do with readability. Although this is a small example, you can see that if several people get involved debugging it, the first thing that gets in the way is your non-standard coding style. If you want to code alone your whole life, do as you like. But the time spent reading and fixing code in the lifetime of any useful software system is greater than the time spent creating the original code. -- http://mail.python.org/mailman/listinfo/python-list I know using semicolons will not optimize the code, but it is actually easier for me to read. I can handle such code better than spacing it out. DCJ -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I not seeing the Error?
On Mon, Aug 12, 2013 at 4:16 PM, Devyn Collier Johnson
wrote:
>
> On 08/12/2013 12:56 PM, Joel Goldstick wrote:
>>
>> On Mon, Aug 12, 2013 at 11:47 AM, Roy Smith wrote:
>>>
>>> I can't quite sort out the multiple quoting levels, but somebody said:
>>>
>> Programming like that is called trolling. A programmer that uses
>> trolling is called a troll. A troll can also refer to such a line
>> of code itself. My scripts contain a lot of trolls. It is easier
>> for me to read trolls than "typical" coding styles.
>>>
>>> Please tell me this is all just an elaborate joke.
>>
>> I was thinking something similar Roy. Devyn, you may think you code
>> differently, but you don't. You have a half of dozen people trying to
>> show you how your style causes confusion between what you think you
>> are writing and what you actually coded. There is plenty of room in
>> coding for personal expression, but what you call 'trolling' is not
>> that. If you like semicolons, use another language that needs them.
>> I think you think it is some version of premature optimization. Since
>> you are a novice at the language, stick with the standards, and learn
>> to embrace them. Ultimately standard coding styles has nothing to do
>> with code optimization. It has to do with readability. Although this
>> is a small example, you can see that if several people get involved
>> debugging it, the first thing that gets in the way is your
>> non-standard coding style. If you want to code alone your whole life,
>> do as you like. But the time spent reading and fixing code in the
>> lifetime of any useful software system is greater than the time spent
>> creating the original code.
>>>
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>>
>
> I know using semicolons will not optimize the code, but it is actually
> easier for me to read. I can handle such code better than spacing it out.
Except it doesn't make it easier to read.
JOB_WRITEURGFILES =
multiprocessing.Process(write2file('./mem/ENGINE_PID', ENGINEPID);
write2file(SENTEMPPATH, ''); write2file(INPUTMEM, ''));
JOB_WRITEURGFILES.start()
As I understand it the above line of code caused you problems. I
don't know what muliprocessing.Process() is supposed to have as
arguments, but I don't think is can have arguments with semicolons,
unless they appeared in a string.
So your semicolons, that you insist make your code easier to read,
have made code that doesn't work, and you don't know why. All I am
saying is you are stating a fact not in evidence. You only think the
semicolons are useful because you haven't taken the time to read and
write enough python code to appreciate that they are not only not
helpful, but they serve no useful purpose. Sure, they allow you to
put several statements on a single line. But that isn't what you were
doing.
good luck. I can see you are interested. keep at it.
>
> DCJ
> --
> http://mail.python.org/mailman/listinfo/python-list
--
Joel Goldstick
http://joelgoldstick.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Am I not seeing the Error?
On 8/12/13 4:16 PM, Devyn Collier Johnson wrote: On 08/12/2013 12:56 PM, Joel Goldstick wrote: On Mon, Aug 12, 2013 at 11:47 AM, Roy Smith wrote: I can't quite sort out the multiple quoting levels, but somebody said: Programming like that is called trolling. A programmer that uses trolling is called a troll. A troll can also refer to such a line of code itself. My scripts contain a lot of trolls. It is easier for me to read trolls than "typical" coding styles. Please tell me this is all just an elaborate joke. I was thinking something similar Roy. Devyn, you may think you code differently, but you don't. You have a half of dozen people trying to show you how your style causes confusion between what you think you are writing and what you actually coded. There is plenty of room in coding for personal expression, but what you call 'trolling' is not that. If you like semicolons, use another language that needs them. I think you think it is some version of premature optimization. Since you are a novice at the language, stick with the standards, and learn to embrace them. Ultimately standard coding styles has nothing to do with code optimization. It has to do with readability. Although this is a small example, you can see that if several people get involved debugging it, the first thing that gets in the way is your non-standard coding style. If you want to code alone your whole life, do as you like. But the time spent reading and fixing code in the lifetime of any useful software system is greater than the time spent creating the original code. -- http://mail.python.org/mailman/listinfo/python-list I know using semicolons will not optimize the code, but it is actually easier for me to read. I can handle such code better than spacing it out. There's no point debating the readability of code that doesn't work. Get it functioning first, then let's talk about how best to format it. --Ned. DCJ -- http://mail.python.org/mailman/listinfo/python-list
Digging into multiprocessing
Hi all, Some work that I'm doing atm is in some serious need of parallelization. As such, I've been digging into the multiprocessing module more than I've had to before and I had a few questions come up as a result: (Running 2.7.5+ on OSX) 1. From what I've read, a new Python interpreter instance is kicked off for every worker. My immediate assumption was that the file that the code was in would be reloaded for every instance. After some digging, this is obviously not the case (print __name__ at the top of the file only yield a single output line). So, I'm assuming that there's some optimization that passes of the bytecode within the interpreter? How, exactly does this work? (I couldn't really find much in the docs about it, or am I just not looking in the right place?) 2. For cases using methods such as map_async/wait, once the bytecode has been passed into the child process, `target` is called `n` times until the current queue is empty. Is this correct? 3. Because __main__ is only run when the root process imports, if using global, READ-ONLY objects, such as, say, a database connection, then it might be better from a performance standpoint to initialize that at main, relying on the interpreter references to be passed around correctly. I've read some blogs and such that suggest that you should create a new database connection within your child process targets (or code called into by the targets). This seems to be less than optimal to me if my assumption is correct. 4. Related to 3, read-only objects that are initialized prior to being passed into a sub-process are safe to reuse as long as they are treated as being immutable. Any other objects should use one of the shared memory features. Is this more or less correct, or am I just off my rocker? Thanks, -- Demian Brecht http://demianbrecht.github.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Could you verify this, Oh Great Unicode Experts of the Python-List?
On 08/11/2013 11:54 PM, Gregory Ewing wrote: > Michael Torrie wrote: >> I've always wondered if the 160 character limit or whatever it is is a >> hard limit in their system, or if it's just a variable they could tweak >> if they felt like it. > > Isn't it for compatibility with SMS? Twitter could > probably change it, but persuading all the cell phone > networks to change at the same time might be rather > difficult. Yes I think you're correct about it being limited for SMS. However I know of no phone or network that won't let you use longer messages; multiple SMS packets are used and most phone paste them back together. So no there's nothing that anyone needs to change to use longer messages if they so chose. It's now just an arbitrary limit, part of the twitter culture. -- http://mail.python.org/mailman/listinfo/python-list
Re: Could you verify this, Oh Great Unicode Experts of the Python-List?
On Tue, Aug 13, 2013 at 2:48 AM, Michael Torrie wrote: > On 08/11/2013 11:54 PM, Gregory Ewing wrote: >> Michael Torrie wrote: >>> I've always wondered if the 160 character limit or whatever it is is a >>> hard limit in their system, or if it's just a variable they could tweak >>> if they felt like it. >> >> Isn't it for compatibility with SMS? Twitter could >> probably change it, but persuading all the cell phone >> networks to change at the same time might be rather >> difficult. > > Yes I think you're correct about it being limited for SMS. > > However I know of no phone or network that won't let you use longer > messages; multiple SMS packets are used and most phone paste them back > together. So no there's nothing that anyone needs to change to use > longer messages if they so chose. It's now just an arbitrary limit, > part of the twitter culture. It's unlikely to be changed; the limit demands brevity. 160 may be arbitrary now, but without strong argument for another cutoff, there's no reason to alter it. And that's my response, in 160 characters. :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: back with more issues
the Classes and __init__ still don't make much sense actually. i have tried and tried again to make it generate numbers between 0 and 5 in a while statement but it just doesn't seem to be working. import random class Player(): hp = 10 def __init__(self, patt): self.att = random.randint(0,5) while Player.hp == 10: print (Player.__init__) atm it seems to be printing "" over and over again, i don't mind the repetition but from my understanding there should be numbers there. numbers that change. crazy frustrating that i just don't understand how this works. -- http://mail.python.org/mailman/listinfo/python-list
Re: Could you verify this, Oh Great Unicode Experts of the Python-List?
>>> I've always wondered if the 160 character limit or whatever it is is a >>> hard limit in their system, or if it's just a variable they could tweak >>> if they felt like it. I thought it was 140 characters? https://twitter.com/about -- http://mail.python.org/mailman/listinfo/python-list
Re: back with more issues
On 13/08/2013 04:13, Kris Mesenbrink wrote: the Classes and __init__ still don't make much sense actually. i have tried and tried again to make it generate numbers between 0 and 5 in a while statement but it just doesn't seem to be working. import random class Player(): This sets an attribute of the class: hp = 10 This method will be called to initialise an instance of the class when one is created: def __init__(self, patt): This sets an attribute of the instance: self.att = random.randint(0,5) while Player.hp == 10: This prints the __init__ method of the class: print (Player.__init__) atm it seems to be printing "" over and over again, i don't mind the repetition but from my understanding there should be numbers there. numbers that change. crazy frustrating that i just don't understand how this works. At no point does it create an instance of the class, so the __init__ method is never called. You can't return anything from the __init__ method because it's called just to initialise the instance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Could you verify this, Oh Great Unicode Experts of the Python-List?
On 13/08/2013 04:20, Jason Friedman wrote: I've always wondered if the 160 character limit or whatever it is is a hard limit in their system, or if it's just a variable they could tweak if they felt like it. I thought it was 140 characters? https://twitter.com/about He did say "or whatever". :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: back with more issues
On Mon, 12 Aug 2013 20:13:31 -0700, Kris Mesenbrink wrote:
> the Classes and __init__ still don't make much sense actually. i have
> tried and tried again to make it generate numbers between 0 and 5 in a
> while statement but it just doesn't seem to be working.
Hi Kris,
You might also find that the tutor mailing list is a better match for
your status as a complete beginner to Python. You can subscribe to it
here:
http://mail.python.org/mailman/listinfo/tutor
If you do, please take my advice and use individual emails, not daily
digests. It is MUCH easier to carry on a back-and-forth conversation with
individual emails.
But for now, you seem to have misunderstood what your code is doing.
Let's start with the basics:
The method __init__ is automatically called by Python when you create a
new instance. You almost never need to call it by hand, so 99% of the
time, if you're writing something like "Player.__init__", you're
probably making a mistake.
But when you do want to call a method -- and remember, you're not
manually calling __init__ -- you need to put round brackets (parentheses
for Americans) after the method name. So you would say something like:
Player.__init__(arguments go inside here)
rather than just Player.__init__. Without the parentheses, you're just
referring to the method, not actually calling it. And without the right
number and type of arguments, you'll get an error.
So how do you create a new Player? Easy -- you just call the *class*, as
if it were a function:
fred = Player()
barney = Player()
wilma = Player()
betty = Player()
Take note of the round brackets. If you leave them out, each of fred,
barney, wilma, betty will be aliases to the Player class, rather than
separate players.
So that's the first thing. Now, another potential problem. Your class
starts off like this:
class Player():
hp = 10
...more code follows
What this does is set a class-wide attribute called "hp", which every
instance shares. Does this matter? Maybe not, it depends on how you use
it. Your sample code doesn't show enough to tell if it will be a problem
or not.
Next, you write this:
> while Player.hp == 10:
> print (Player.__init__)
but since nothing in the loop changes the value of Player.hp, this will
loop forever, or until you interrupt it. So I'm not really sure what you
actually intend to do.
My guess is that what you actually want is something like this:
for i in range(10):
player = Player()
print("Player", i, "has value", player.attr)
This ought to get you started.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Re: Calling Python macro from ctypes
On Mon, 12 Aug 2013 13:42:14 +0200, Peter Otten wrote: > Steven D'Aprano wrote: > >> Is it possible to call a Python macro from ctypes? For example, Python >> 3.3 introduces some new macros for querying the internal representation >> of strings: >> >> http://www.python.org/dev/peps/pep-0393/#new-api [...] > That's not possible. It may look like a function, but a preprocessor > replaces the C macro in the C source before compilation. That's what I feared. In that case, how would I use ctypes to access the underlying fields in the new string implementation? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
