Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am going to use a library called socket.io-python-emitter (https://github.com/ziyasal/socket.io-python-emitter) in my project, however, the syntax it introduces really bothers me..
Example usage:
e = Emitter(...)
e.Emit('message')
e.In('group1').Emit('message')
e.In('group1').In('group2').Emit('message')
e.Of("/ns").In('group1').In('group2').Emit('message')
I guess the author have done it this way so the JavaScript/node.js people will feel more at home, but it it really makes it harder to code a dynamic emitter..
Ultimately, it should be (at least in my opinion):
e = Emitter(...)
e.emit('message')
e.emit('message', groups=['group1'])
e.emit('message', groups=['group1', 'group2'])
e.emit('message', groups=['group1', 'group2'], ns='/ns')
What is the best approach?
Create a wrapper around this lib? Seams like that would be ugly...
Fork the project and create a "pythonic" version? More ugly, and duplication.. Dont really want to do this.
Submit a patch to add a pythonic way to the upstream project?
Your third option seems (to me, of course) the good approach. I would first talk to the author(s)/maintainer(s) to see how they feel about the idea.
Since you create a new method (and use keywords arguments anyway), both syntaxes can coexist, so I think there is no need to fork the project or create a wrapper.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I'm sorry if I'm not asking this correctly. It may be due to a lack of understanding.
If I was explaining to someone how to understand of a piece of code that's been written by someone else..I would say something like:
"Ok so here we have this method getting called and it's taking one argument. Let's find the method declaration itself and see what it's doing and what it's doing to our argument."
Is there a concise way of describing looking at code backwards in a way? Following the sequence of events? Flow of execution? Flow/order of operations?
Thank you.
My professors refer to it as tracing a function. It might be linked to localisation (I'm in France and translating their word into English) or to a specific language, but that's what I got and it sounds right.
I think this bit of Python doc supports my proposed answer.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
is it a good practice that i usually (tend to) do in python?
making shortcut of functions for example:
p = print
and the i use:
p('hello world')
or
p(2**5)
does it affect on performance? What is your suggestion, is it OK?
A good practice in Python is: easy is better. You do not give much clarity in your code by doing that (and depending on the IDE-highlighting strategy, make it even worse for others). Furthermore, the choice of your shortcut, namely p, is really a bad idea. How about people writing code with prime numbers (and P is not a good idea too).
For performances, there is no gain I think. Since print is a built-in function, you actually add a variable inside globals() or locals(). In my opinion, this is 1) not a good practice to use shortcuts like that 2) not an improvement in performance.
I have no idea if it is a good practice in python, but in general I would say no.
It will take away readability for other readers of your code. If the codebase grows large and you replace a lot of functions with very short names you make it difficult to read in general.
Coming from many years of code maintenance if I was called out in the middle of the night to fix a code problem in production and found code like that I am pretty sure I would hunt you down in the morning and ask why you would ever do such a thing.
If you are lazy and doesn't want to write so much - get your self an editor that can complete code for you instead.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I never went too far into NetLogo, and being a novice in Python I started looking into the turtle module, aiming towards ABM. I have seen some simple implementations of the turtle module (turtledemo and YouTube) but none were comparable to NetLogo library's examples. I went over (once) the mesa tutorials and it seemed interesting but, as it says, more advanced stuff require Javascript. I've also read that NetLogo is fast to pick up.
Considering the above, and adding your own experience, could NetLogo be a better choice than Python? Could you estimate how hard each path would be? Do you have any other suggestions?
I teach ABM. I used to use Python for my course,
using a module that provides some NetLogo-like functionality:
https://raw.githubusercontent.com/alan-isaac/econpy/master/abm/gridworld/gridworld.py
I gave that up. Although Python is a great language for
teaching programming, NetLogo is a much better language for
teaching ABM. (Both started out as teaching languages,
very roughly speaking, and became much more.) It is very
easy to get started with NetLogo. It's builtin facilities
also support very sophisticated model building. These facilities
can be extended when needed.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I just want to know if it's possible to use WHMCS with Django framework ?
Thank in advance !
Yes, it is most definitely possible, but your question lacks some clarity... Aside from the fact that everything is possible if you really put your mind to it (except time travel - I tried), you can use some of the libraries that nice people have written for nice people like you. Some examples:
https://github.com/jawr/django-whmcs
https://pypi.python.org/pypi/pywhmcs/0.0.2
You will definitely run into problems with newer versions of WHMCS and Django since the libraries haven't been updated since the stone age - but you have something to build on. That often counts for more than you can expect.
But TL;DR (answer in the same style as the question): Yes.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a huge C file (~100k lines) which I need to be able to parse. Mainly I need to be able to get details about individual fields of every structure (like field name and type for every field in the structure) from its definition. Is there a good(open source, which i can use in my code) way to do this already? Or should I write my own parser for this. If I have to write my own, can anyone suggest a good place to start? I have never worked with python before.
Thanks
Take a look at this link for an extensive list of parsing tools available for Python. Specifically, for parsing c code, try the pycparser
The right way to do this is almost certainly to interface with the front-end of an existing compiler, such as gcc, then work with the intermediate representation, rather than attempting to create your own parser, in any language.
However, pycparser, as suggested by Dhara might well be a good substitute, and definitely better than any attempt to roll your own.