Re: Best way to go about embedding python

2016-11-13 Thread Michael Torrie
On 11/13/2016 08:40 PM, Kaylen Wheeler wrote: > I wonder if Lua would be a better option. Does it suffer from the > same sandboxing issues that python does? Lua was designed for this sort of thing and it can be secured and sandboxed. -- https://mail.python.org/mailman/listinfo/python-list

Re: if iter(iterator) is iterator

2016-11-13 Thread eryk sun
On Mon, Nov 14, 2016 at 6:25 AM, Serhiy Storchaka wrote: > On 14.11.16 02:40, Steve D'Aprano wrote: >> >> I'm surprised that the inspect module doesn't appear to have isiterable >> and isiterator functions. Here's my first attempt at both: > > Just use isinstance() with collections ABC classes. E

Re: if iter(iterator) is iterator

2016-11-13 Thread Serhiy Storchaka
On 14.11.16 02:40, Steve D'Aprano wrote: I'm surprised that the inspect module doesn't appear to have isiterable and isiterator functions. Here's my first attempt at both: Just use isinstance() with collections ABC classes. -- https://mail.python.org/mailman/listinfo/python-list

Re: if iter(iterator) is iterator

2016-11-13 Thread Steven D'Aprano
On Monday 14 November 2016 16:04, Chris Angelico wrote: > True, but ISTR there being a possibility that __iter__ could raise to > indicate that this isn't actually iterable. Maybe I'm recalling wrong. If __iter__ raises, that's a bug :-) Raising an exception from __iter__ appears to just fall th

Re: Access to the caller's globals, not your own

2016-11-13 Thread eryk sun
On Mon, Nov 14, 2016 at 5:20 AM, Steven D'Aprano wrote: > but what magic do I need? globals() is no good, because it returns the > library's global namespace, not the caller's. > > Any solution ought to work for CPython, IronPython and Jython, at a minimum. You can access the globals of the calle

Access to the caller's globals, not your own

2016-11-13 Thread Steven D'Aprano
Suppose I have a library function that reads a global configuration setting: # Toy example SPAMIFY = True def make_spam(n): if SPAMIFY: return "spam"*n else: return "ham"*n Don't tell me to make SPAMIFY a parameter of the function. I know that. That's what I would normal

Re: Best way to go about embedding python

2016-11-13 Thread Gregory Ewing
Michael Torrie wrote: And such bindings may need to be two-way. For example in Python code you may want to instantiate some new instance of game object, and you'll need to make sure that the wrapper code will create the appropriate in-game object. Another thing that can be tricky about this is

Re: if iter(iterator) is iterator

2016-11-13 Thread Chris Angelico
On Mon, Nov 14, 2016 at 3:54 PM, Steven D'Aprano wrote: >> Any particular reason to write it that way, rather than: >> >> def isiterable(obj): >> try: >> iter(obj) >> return True >> except TypeError: >> return False > > > class BadIterable: > def __iter__(self):

Re: Making stl files with python for 3d printing

2016-11-13 Thread Gregory Ewing
Poul Riis wrote: However, when sending the .stl file produced to a 3D-printer the vase comes out as a filled solid - no room for water and flowers! My guess is that you have a problem with the orientation of your faces. The inner surface needs to have its triangles oriented so that their "outsi

Re: if iter(iterator) is iterator

2016-11-13 Thread Steven D'Aprano
On Monday 14 November 2016 11:59, Chris Angelico wrote: > On Mon, Nov 14, 2016 at 11:40 AM, Steve D'Aprano > wrote: >> def isiterable(obj): >> """Return True if obj is an iterable, and False otherwise. >> >> Iterable objects can be iterated over, and they provide either >> an __iter__

Re: Best way to go about embedding python

2016-11-13 Thread Kaylen Wheeler
I wonder if Lua would be a better option. Does it suffer from the same sandboxing issues that python does? On Sunday, 13 November 2016 17:38:23 UTC-8, Nathan Ernst wrote: > In regards to performance of Lua vs Python, I don't have enough (near zero > experience) with Lua to comment there. > > B

help on "from deen import *" vs. "import deen"

2016-11-13 Thread jfong
Running the following codes (deen.py) under Win32 python 3.4.4 terminal: tbli = [0x66, 0x27, 0xD0] tblm = [0 for x in range(3)] def gpa(data): td = data ^ tblm[2] return td I can get a correct answer this way: >>> import deen >>> deen.tblm = deen.tbli >>> deen.gpa(0x7d) 173 # 0xad (= 0x7

Re: Best way to go about embedding python

2016-11-13 Thread Nathan Ernst
In regards to performance of Lua vs Python, I don't have enough (near zero experience) with Lua to comment there. But in regards to embedding in a game, the only experience I have w/ Python being embedded is while working on modding Civilization IV. What I saw there just made me nauseous. The rea

Re: Best way to go about embedding python

2016-11-13 Thread Michael Torrie
On 11/13/2016 12:10 AM, kfjwhee...@gmail.com wrote: > 2. How would I go about including python scripts to run with the > engine. Would the .py files from the standard libraries be > necessary, or is anything built in? It's usually just a matter of asking the python instance to load and run the s

Re: Best way to go about embedding python

2016-11-13 Thread Chris Angelico
On Mon, Nov 14, 2016 at 11:40 AM, Steve D'Aprano wrote: > On Mon, 14 Nov 2016 12:23 am, Chris Angelico wrote: > >> Python without its stdlib is a disappointingly featureless >> language :) > > > I don't think that's true. You can do a lot in Python without any imports in > your code: > > - basic s

Re: if iter(iterator) is iterator

2016-11-13 Thread Chris Angelico
On Mon, Nov 14, 2016 at 11:40 AM, Steve D'Aprano wrote: > def isiterable(obj): > """Return True if obj is an iterable, and False otherwise. > > Iterable objects can be iterated over, and they provide either > an __iter__ method or a __getitem__ method. > > Iteration over an object

Re: Best way to go about embedding python

2016-11-13 Thread Steve D'Aprano
On Mon, 14 Nov 2016 12:23 am, Chris Angelico wrote: > Python without its stdlib is a disappointingly featureless > language :) I don't think that's true. You can do a lot in Python without any imports in your code: - basic string processing - BigNum (int) and float arithmetic - lists and tuples

Re: if iter(iterator) is iterator

2016-11-13 Thread Steve D'Aprano
On Mon, 14 Nov 2016 07:02 am, Antoon Pardon wrote: > > Some time ago I read a text or saw a video on iterators and one thing > I remember from it, is that you should do something like the following > when working with iterators, to avoid some pitt falls. > > def bar(iterator): > if iter(iter

Making stl files with python for 3d printing

2016-11-13 Thread Poul Riis
Below you can find my python code to make a vase for 3D-printing. The vase looks nice on my screen so the vertices and the faces seem to be perfect. However, when sending the .stl file produced to a 3D-printer the vase comes out as a filled solid - no room for water and flowers! I have tried to s

Re: if iter(iterator) is iterator

2016-11-13 Thread Chris Angelico
On Mon, Nov 14, 2016 at 8:57 AM, Gregory Ewing wrote: > Antoon Pardon wrote: > >> def bar(iterator): >> if iter(iterator) is iterator: >> ... > > > That's a way of finding out whether you can safely iterate > over something more than once. If the object is already an > iterator, applyi

Re: Halp in if

2016-11-13 Thread Erik
Hi, On 13/11/16 20:09, menta...@gmail.com wrote: HI want to make a script that if somthing happens, it stop, and if it doesnt, it couninues. I dont finding a smart way. Read the documentation for the "while", "break" and "continue" keywords. Regards, E. -- https://mail.python.org/mailman/li

Re: if iter(iterator) is iterator

2016-11-13 Thread Gregory Ewing
Antoon Pardon wrote: def bar(iterator): if iter(iterator) is iterator: ... That's a way of finding out whether you can safely iterate over something more than once. If the object is already an iterator, applying iter() to it will return the same object, and iterating over it will c

Re: if iter(iterator) is iterator

2016-11-13 Thread Chris Angelico
On Mon, Nov 14, 2016 at 7:02 AM, Antoon Pardon wrote: > Some time ago I read a text or saw a video on iterators and one thing > I remember from it, is that you should do something like the following > when working with iterators, to avoid some pitt falls. > > def bar(iterator): > if iter(itera

Halp in if

2016-11-13 Thread menta231
Hii there I am preety New at python, and i need your help. I want to make a script that if somthing happens, it stop, and if it doesnt, it couninues. I dont finding a smart way. Here is what i wrote. I want to do it without exits and sleeps. import time print ("hello there ") x = raw_input ("

if iter(iterator) is iterator

2016-11-13 Thread Antoon Pardon
Some time ago I read a text or saw a video on iterators and one thing I remember from it, is that you should do something like the following when working with iterators, to avoid some pitt falls. def bar(iterator): if iter(iterator) is iterator: ... However I can't relocate it and ca

Re: how to print variable few time?

2016-11-13 Thread Jussi Piitulainen
andy writes: > Sat, 12 Nov 2016 04:58:20 -0800 wrote guy asor: > >> hello! >> >> this is my code: >> >> word=raw_input() >> print word*3 >> >> >> with this code im getting - wordwordword. >> what changes i need to make to get - word word word - instead? >> >> thanks > > using python3.x: > > w

Re: how to print variable few time?

2016-11-13 Thread andy
Sun, 13 Nov 2016 15:12:01 +0100 wrote andy: > word=input() > print((word+' ')*2, end='') > print(word) > > ..but D'Apranos ' '.join(..) is far more elegant. don't know whether I really would use this form, but it works in python3: word = ' '.join([input()]*3) print(word) -- https://mail.pytho

Re: how to print variable few time?

2016-11-13 Thread andy
Sat, 12 Nov 2016 04:58:20 -0800 wrote guy asor: > hello! > > this is my code: > > word=raw_input() > print word*3 > > > with this code im getting - wordwordword. > what changes i need to make to get - word word word - instead? > > thanks using python3.x: word=input() print((word+' ')*2, end

Re: Best way to go about embedding python

2016-11-13 Thread Chris Angelico
On Sun, Nov 13, 2016 at 6:10 PM, wrote: > > (Sorry about the last post, my finger slipped before I was finished, and I > can't delete it for some reason.) (That's because this is a mailing list and newsgroup gatewayed to each other. Once sent, a message cannot be edited or deleted.) > A friend

Re: Best way to go about embedding python

2016-11-13 Thread Ben Finney
kfjwhee...@gmail.com writes: > A friend of mine is developing a game engine, and I would like to > extend the engine by adding some scripting functionality. I haven't done it myself. But the Python Wiki has some pages that will help you, I think: * https://wiki.python.org/moin/AppsWithPythonScr