Q_Id
int64 337
49.3M
| CreationDate
stringlengths 23
23
| Users Score
int64 -42
1.15k
| Other
int64 0
1
| Python Basics and Environment
int64 0
1
| System Administration and DevOps
int64 0
1
| Tags
stringlengths 6
105
| A_Id
int64 518
72.5M
| AnswerCount
int64 1
64
| is_accepted
bool 2
classes | Web Development
int64 0
1
| GUI and Desktop Applications
int64 0
1
| Answer
stringlengths 6
11.6k
| Available Count
int64 1
31
| Q_Score
int64 0
6.79k
| Data Science and Machine Learning
int64 0
1
| Question
stringlengths 15
29k
| Title
stringlengths 11
150
| Score
float64 -1
1.2
| Database and SQL
int64 0
1
| Networking and APIs
int64 0
1
| ViewCount
int64 8
6.81M
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
433,945 | 2009-01-11T23:03:00.000 | 0 | 0 | 1 | 0 | java,python,jfilechooser | 433,977 | 6 | false | 0 | 1 | Maybe you would like to take a look at Jython. | 2 | 4 | 0 | I was wondering if there is something similar to Java's JFileChooser for Python?
JFileChooser is a graphical front end to choose a file.
Preferably something that is already with Python. Maybe with Tkinter. | JFileChooser for Python? | 0 | 0 | 0 | 2,182 |
434,407 | 2009-01-12T04:05:00.000 | 0 | 0 | 1 | 0 | python,virtualenv,buildout | 436,427 | 5 | false | 1 | 0 | The other option (one I've used) is to easy_install Django after you've created the virtual environment. This is easily scripted. The penalty you pay is waiting for Django installation in each of your virtual environments.
I'm with Toby, though: Unless there's a compelling reason why you have to have a separate copy of Django in each virtual environment, you should just consider installing it in your main Python area, and allowing each virtual environment to use it from there. | 2 | 2 | 0 | So, I want to start using virtualenv this year. I like the no-site-packages option, that is nice. However I was wondering how to install certain packages into each virtualenv. For example, lets say I want to install django into each virtualenv... is this possible, and if so, how? Does buildout address this?
Well it's not so much django, more like the django applications... I dont mind installing a version of django into each virtualenv... i was just wondering if there was some intermediate option to 'no-site-packages' | Installing certain packages using virtualenv | 0 | 0 | 0 | 3,218 |
434,407 | 2009-01-12T04:05:00.000 | 2 | 0 | 1 | 0 | python,virtualenv,buildout | 434,445 | 5 | false | 1 | 0 | If you want django to be installed on EACH virtualenv, you might as well install it in the site-packages directory? Just a thought. | 2 | 2 | 0 | So, I want to start using virtualenv this year. I like the no-site-packages option, that is nice. However I was wondering how to install certain packages into each virtualenv. For example, lets say I want to install django into each virtualenv... is this possible, and if so, how? Does buildout address this?
Well it's not so much django, more like the django applications... I dont mind installing a version of django into each virtualenv... i was just wondering if there was some intermediate option to 'no-site-packages' | Installing certain packages using virtualenv | 0.07983 | 0 | 0 | 3,218 |
434,580 | 2009-01-12T06:07:00.000 | 0 | 0 | 0 | 0 | python,web-hosting,wsgi | 434,598 | 9 | false | 1 | 0 | I've been pretty happy with Dreamhost, and of course Google AppEngine. | 3 | 14 | 0 | I want to be able to run WSGI apps but my current hosting restricts it. Does anybody know a company that can accommodate my requirements? | For Python support, what company would be best to get hosting from? | 0 | 0 | 0 | 9,246 |
434,580 | 2009-01-12T06:07:00.000 | 0 | 0 | 0 | 0 | python,web-hosting,wsgi | 435,197 | 9 | false | 1 | 0 | Google App engine and OpenHosting.com
Have virtual server by OpenHosting, they are ultra fast with support and have very high uptime. | 3 | 14 | 0 | I want to be able to run WSGI apps but my current hosting restricts it. Does anybody know a company that can accommodate my requirements? | For Python support, what company would be best to get hosting from? | 0 | 0 | 0 | 9,246 |
434,580 | 2009-01-12T06:07:00.000 | 0 | 0 | 0 | 0 | python,web-hosting,wsgi | 22,368,517 | 9 | false | 1 | 0 | I use AWS micro server, 1 year free and after that you can get a 3 year reserved which works out to about $75/yr :) The micro server has only 20MB/sec throughput, ~600MB of ram, and a slower CPU. I run a few Mezzanine sites on mine and it seems fine. | 3 | 14 | 0 | I want to be able to run WSGI apps but my current hosting restricts it. Does anybody know a company that can accommodate my requirements? | For Python support, what company would be best to get hosting from? | 0 | 0 | 0 | 9,246 |
434,597 | 2009-01-12T06:23:00.000 | 2 | 0 | 1 | 1 | python,windows,macos | 818,083 | 15 | false | 0 | 0 | If you want to specify the app to open the file with on Mac OS X, use this:
os.system("open -a [app name] [file name]") | 2 | 157 | 0 | I need to be able to open a document using its default application in Windows and Mac OS. Basically, I want to do the same thing that happens when you double-click on the document icon in Explorer or Finder. What is the best way to do this in Python? | Open document with default OS application in Python, both in Windows and Mac OS | 0.02666 | 0 | 0 | 118,227 |
434,597 | 2009-01-12T06:23:00.000 | 5 | 0 | 1 | 1 | python,windows,macos | 24,895,085 | 15 | false | 0 | 0 | os.startfile(path, 'open') under Windows is good because when spaces exist in the directory, os.system('start', path_name) can't open the app correctly and when the i18n exist in the directory, os.system needs to change the unicode to the codec of the console in Windows. | 2 | 157 | 0 | I need to be able to open a document using its default application in Windows and Mac OS. Basically, I want to do the same thing that happens when you double-click on the document icon in Explorer or Finder. What is the best way to do this in Python? | Open document with default OS application in Python, both in Windows and Mac OS | 0.066568 | 0 | 0 | 118,227 |
436,497 | 2009-01-12T18:38:00.000 | 23 | 0 | 1 | 0 | python,module,package,python-import | 436,511 | 5 | false | 0 | 0 | This doesn't exactly answer your question, but I'm going to suggest that you move the function outside of the __init__.py file, and into another module inside that package. You can then easily import that function into your other module. If you want, you can have an import statement in the __init__.py file that will import that function (when the package is imported) as well. | 3 | 62 | 0 | In a module residing inside a package, i have the need to use a function defined within the __init__.py of that package. how can i import the package within the module that resides within the package, so i can use that function?
Importing __init__ inside the module will not import the package, but instead a module named __init__, leading to two copies of things with different names...
Is there a pythonic way to do this? | Python: import the containing package | 1 | 0 | 0 | 36,370 |
436,497 | 2009-01-12T18:38:00.000 | 5 | 0 | 1 | 0 | python,module,package,python-import | 436,607 | 5 | false | 0 | 0 | If the package is named testmod and your init file is therefore testmod/__init__.py and your module within the package is submod.py then from within submod.py file, you should just be able to say import testmod and use whatever you want that's defined in testmod. | 3 | 62 | 0 | In a module residing inside a package, i have the need to use a function defined within the __init__.py of that package. how can i import the package within the module that resides within the package, so i can use that function?
Importing __init__ inside the module will not import the package, but instead a module named __init__, leading to two copies of things with different names...
Is there a pythonic way to do this? | Python: import the containing package | 0.197375 | 0 | 0 | 36,370 |
436,497 | 2009-01-12T18:38:00.000 | 1 | 0 | 1 | 0 | python,module,package,python-import | 708,076 | 5 | false | 0 | 0 | In Django, the file manage.py has from django.core.management import execute_manager, but execute_manager is not a module. It is a function within the __init__.py module of the management directory. | 3 | 62 | 0 | In a module residing inside a package, i have the need to use a function defined within the __init__.py of that package. how can i import the package within the module that resides within the package, so i can use that function?
Importing __init__ inside the module will not import the package, but instead a module named __init__, leading to two copies of things with different names...
Is there a pythonic way to do this? | Python: import the containing package | 0.039979 | 0 | 0 | 36,370 |
436,944 | 2009-01-12T20:40:00.000 | 0 | 0 | 1 | 0 | python,django,django-forms | 437,360 | 2 | false | 1 | 0 | The Django source says
Given a
dictionary of data and this widget's
name, returns the value of this
widget. Returns None if it's not
provided.
Reading the code, I see that Django's separate Date and Time widgets are both subclasses of Input, subclasses of Widget, which appears to work with simple Strings. | 1 | 5 | 0 | I'm trying to build my own custom django form widgets (putting them in widgets.py of my project directory). What should the value "value_from_datadict()" return? Is it returning a string or the actual expected value of the field?
I'm building my own version of a split date/time widget using JQuery objects, what should each part of the widget return? Should the date widget return a datetime and the time widget return a datetime? What glue code merges the two values together? | What should "value_from_datadict" method of a custom form widget return? | 0 | 0 | 0 | 4,106 |
437,025 | 2009-01-12T21:11:00.000 | -1 | 0 | 1 | 1 | python,readline,read-eval-print-loop | 439,403 | 6 | false | 0 | 0 | I think you have 2 basic options:
Synchronize your output (i.e. block until it comes back)
Separate your input and your (asyncronous) output, perhaps in two separate columns. | 1 | 13 | 0 | I have a Python-based app that can accept a few commands in a simple read-eval-print-loop. I'm using raw_input('> ') to get the input. On Unix-based systems, I also import readline to make things behave a little better. All this is working fine.
The problem is that there are asynchronous events coming in, and I'd like to print output as soon as they happen. Unfortunately, this makes things look ugly. The "> " string doesn't show up again after the output, and if the user is halfway through typing something, it chops their text in half. It should probably redraw the user's text-in-progress after printing something.
This seems like it must be a solved problem. What's the proper way to do this?
Also note that some of my users are Windows-based.
TIA
Edit: The accepted answer works under Unixy platforms (when the readline module is available), but if anyone knows how to make this work under Windows, it would be much appreciated! | How to implement a python REPL that nicely handles asynchronous output? | -0.033321 | 0 | 0 | 7,222 |
438,149 | 2009-01-13T06:42:00.000 | 0 | 1 | 1 | 0 | python,class,scripting | 1,992,389 | 4 | false | 0 | 0 | not necessary since python is not a purely object oriented language but certain things are better written in classes (encapsulation).it becomes easier to build a large project using classes | 3 | 0 | 0 | I am creating an interface for Python scripting.
Later I will be dong Python scripting also for automated testing.
Is it necessary the at i must use class in my code.Now I have created the code
with dictionaries,lists,functions,global and local variables.
Is class necessary?
Help me in this. | Help needed--Is class necessary in Python scripting? | 0 | 0 | 0 | 2,284 |
438,149 | 2009-01-13T06:42:00.000 | 1 | 1 | 1 | 0 | python,class,scripting | 438,239 | 4 | false | 0 | 0 | It's not needed to make it work, but I would argue that it will become messy to maintain if you do not encapsulate certain things in classes. Classes are something that schould help the programmer to organizes his/her code, not just nice to have fluff. | 3 | 0 | 0 | I am creating an interface for Python scripting.
Later I will be dong Python scripting also for automated testing.
Is it necessary the at i must use class in my code.Now I have created the code
with dictionaries,lists,functions,global and local variables.
Is class necessary?
Help me in this. | Help needed--Is class necessary in Python scripting? | 0.049958 | 0 | 0 | 2,284 |
438,149 | 2009-01-13T06:42:00.000 | 10 | 1 | 1 | 0 | python,class,scripting | 438,171 | 4 | false | 0 | 0 | No, of course class is not a must. As Python is a scripting language, you can simply code your scripts without defining your own classes.
Classes are useful if you implement a more complex program which needs a structured approach and OOP benfits (encapsulation, polimorphism) help you in doing it. | 3 | 0 | 0 | I am creating an interface for Python scripting.
Later I will be dong Python scripting also for automated testing.
Is it necessary the at i must use class in my code.Now I have created the code
with dictionaries,lists,functions,global and local variables.
Is class necessary?
Help me in this. | Help needed--Is class necessary in Python scripting? | 1 | 0 | 0 | 2,284 |
438,559 | 2009-01-13T10:36:00.000 | 4 | 0 | 0 | 0 | python,mysql,database,django,django-models | 438,700 | 2 | false | 1 | 0 | No.
Adding indexes willy-nilly to all "slow" queries will also slow down inserts, updates and deletes.
Indexes are a balancing act between fast queries and fast changes. There is no general or "right" answer. There's certainly nothing that can automate this.
You have to measure the improvement across your whole application as you add and change indexes. | 1 | 5 | 0 | The beauty of ORM lulled me into a soporific sleep. I've got an existing Django app with a lack of database indexes. Is there a way to automatically generate a list of columns that need indexing?
I was thinking maybe some middleware that logs which columns are involved in WHERE clauses? but is there anything built into MySQL that might help? | Is there a way to automatically generate a list of columns that need indexing? | 0.379949 | 1 | 0 | 620 |
438,844 | 2009-01-13T12:53:00.000 | 159 | 0 | 1 | 0 | python,goto | 438,848 | 22 | false | 0 | 0 | No, Python does not support labels and goto. It's a (highly) structured programming language. | 1 | 250 | 0 | Is there a goto or any equivalent in Python to be able to jump to a specific line of code? | Is there a label/goto in Python? | 1 | 0 | 0 | 616,022 |
438,894 | 2009-01-13T13:13:00.000 | 6 | 0 | 1 | 0 | python,exception-handling | 438,901 | 6 | false | 0 | 0 | As far as I know, if an exception is not caught by your script, it will be interrupted. | 2 | 75 | 0 | I need to stop my program when an exception is raised in Python.
How do I implement this? | How do I stop a program when an exception is raised in Python? | 1 | 0 | 0 | 188,945 |
438,894 | 2009-01-13T13:13:00.000 | 17 | 0 | 1 | 0 | python,exception-handling | 440,523 | 6 | false | 0 | 0 | If you don't handle an exception, it will propagate up the call stack up to the interpreter, which will then display a traceback and exit. IOW : you don't have to do anything to make your script exit when an exception happens. | 2 | 75 | 0 | I need to stop my program when an exception is raised in Python.
How do I implement this? | How do I stop a program when an exception is raised in Python? | 1 | 0 | 0 | 188,945 |
439,641 | 2009-01-13T16:21:00.000 | 7 | 1 | 1 | 0 | python,ruby,python-imaging-library,rmagick | 440,298 | 3 | false | 0 | 0 | PIL is a good library, use it. ImageMagic (what RMagick wraps) is a very heavy library that should be avoided if possible. Its good for doing local processing of images, say, a batch photo editor, but way too processor inefficient for common image manipulation tasks for web.
EDIT: In response to the question, PIL supports drawing vector shapes. It can draw polygons, curves, lines, fills and text. I've used it in a project to produce rounded alpha corners to PNG images on the fly over the web. It essentially has most of the drawing features of GDI+ (in Windows) or GTK (in Gnome on Linux). | 1 | 4 | 0 | For my next project I plan to create images with text and graphics. I'm comfortable with ruby, but interested in learning python. I figured this may be a good time because PIL looks like a great library to use. However, I don't know how it compares to what ruby has to offer (e.g. RMagick and ruby-gd). From what I can gather PIL had better documentation (does ruby-gd even have a homepage?) and more features. Just wanted to hear a few opinions to help me decide.
Thanks.
Vince | PIL vs RMagick/ruby-gd | 1 | 0 | 0 | 2,243 |
439,759 | 2009-01-13T16:47:00.000 | 0 | 0 | 0 | 0 | php,python,postgresql | 494,119 | 7 | false | 0 | 0 | Just to throw it out there... there are PHP frameworks utilizing MVC.
Codeigniter does simple and yet powerful things. You can definitely separate the template layer from the logic layer. | 6 | 2 | 0 | I'm looking for some quick thoughts about a business application I am looking to build. I'd like to separate the three layers of presentation, domain logic, and data using PHP, Python, and PostgreSQL, respectively. I would like to hear, possibly from other folks who have gone down this path before, if there are problems with this approach, if I am targeting the wrong tools, etc.
I'm looking at PHP because it is widely used, fairly mature, and I can find ample people with skills in PHP interface design.
I'm looking at Python because of the benefits of readable code, because I hear can find more Python programmers that also have subject-matter skills (in this case, finance), and it's an open source language. Plus, it seems easier to code with.
I'm looking at PostgreSQL for the transaction-level features. MySQL is also an option here, but I don't need to debate this aspect.
This is not a web application, although I would like to utilize a browser for the user interface. This is more of an Enterprise Application, but for a small business with moderate numbers of users (maybe 5-10) and a modest number of daily transactions.
What is important is that we are able to upgrade the database or domain logic or interface separate from the other layers in the future.
I'm NOT looking for a buy vs. build debate, as that's a different discussion.
Thanks for any insight | Is a PHP, Python, PostgreSQL design suitable for a business application? | 0 | 1 | 0 | 2,512 |
439,759 | 2009-01-13T16:47:00.000 | 0 | 0 | 0 | 0 | php,python,postgresql | 439,793 | 7 | false | 0 | 0 | I personally agree with the second and the third points in your post. Speaking about PHP, in my opinion you can use Python also for presentation, there are many solutions (Zope, Plone ...) based on Python. | 6 | 2 | 0 | I'm looking for some quick thoughts about a business application I am looking to build. I'd like to separate the three layers of presentation, domain logic, and data using PHP, Python, and PostgreSQL, respectively. I would like to hear, possibly from other folks who have gone down this path before, if there are problems with this approach, if I am targeting the wrong tools, etc.
I'm looking at PHP because it is widely used, fairly mature, and I can find ample people with skills in PHP interface design.
I'm looking at Python because of the benefits of readable code, because I hear can find more Python programmers that also have subject-matter skills (in this case, finance), and it's an open source language. Plus, it seems easier to code with.
I'm looking at PostgreSQL for the transaction-level features. MySQL is also an option here, but I don't need to debate this aspect.
This is not a web application, although I would like to utilize a browser for the user interface. This is more of an Enterprise Application, but for a small business with moderate numbers of users (maybe 5-10) and a modest number of daily transactions.
What is important is that we are able to upgrade the database or domain logic or interface separate from the other layers in the future.
I'm NOT looking for a buy vs. build debate, as that's a different discussion.
Thanks for any insight | Is a PHP, Python, PostgreSQL design suitable for a business application? | 0 | 1 | 0 | 2,512 |
439,759 | 2009-01-13T16:47:00.000 | 0 | 0 | 0 | 0 | php,python,postgresql | 439,818 | 7 | false | 0 | 0 | Just skip PHP and use Python (with Django, as already noticed while I typed). Django already separates the layers as you mentioned.
I have never used PgSQL myself, but I think it's mostly a matter of taste whether you prefer it over MySQL. It used to support more enterprise features than MySQL but I'm not sure if that's still true with MySQL 5.0 and 5.1. Transactions are supported in MySQL, anyway (you have to use the InnoDB table engine, however). | 6 | 2 | 0 | I'm looking for some quick thoughts about a business application I am looking to build. I'd like to separate the three layers of presentation, domain logic, and data using PHP, Python, and PostgreSQL, respectively. I would like to hear, possibly from other folks who have gone down this path before, if there are problems with this approach, if I am targeting the wrong tools, etc.
I'm looking at PHP because it is widely used, fairly mature, and I can find ample people with skills in PHP interface design.
I'm looking at Python because of the benefits of readable code, because I hear can find more Python programmers that also have subject-matter skills (in this case, finance), and it's an open source language. Plus, it seems easier to code with.
I'm looking at PostgreSQL for the transaction-level features. MySQL is also an option here, but I don't need to debate this aspect.
This is not a web application, although I would like to utilize a browser for the user interface. This is more of an Enterprise Application, but for a small business with moderate numbers of users (maybe 5-10) and a modest number of daily transactions.
What is important is that we are able to upgrade the database or domain logic or interface separate from the other layers in the future.
I'm NOT looking for a buy vs. build debate, as that's a different discussion.
Thanks for any insight | Is a PHP, Python, PostgreSQL design suitable for a business application? | 0 | 1 | 0 | 2,512 |
439,759 | 2009-01-13T16:47:00.000 | 1 | 0 | 0 | 0 | php,python,postgresql | 440,496 | 7 | false | 0 | 0 | I can only repeat what other peoples here already said : if you choose Python for the domain layer, you won't gain anything (quite on the contrary) using PHP for the presentation layer. Others already advised Django, and that might be a pretty good choice, but there's no shortage of good Python web frameworks. | 6 | 2 | 0 | I'm looking for some quick thoughts about a business application I am looking to build. I'd like to separate the three layers of presentation, domain logic, and data using PHP, Python, and PostgreSQL, respectively. I would like to hear, possibly from other folks who have gone down this path before, if there are problems with this approach, if I am targeting the wrong tools, etc.
I'm looking at PHP because it is widely used, fairly mature, and I can find ample people with skills in PHP interface design.
I'm looking at Python because of the benefits of readable code, because I hear can find more Python programmers that also have subject-matter skills (in this case, finance), and it's an open source language. Plus, it seems easier to code with.
I'm looking at PostgreSQL for the transaction-level features. MySQL is also an option here, but I don't need to debate this aspect.
This is not a web application, although I would like to utilize a browser for the user interface. This is more of an Enterprise Application, but for a small business with moderate numbers of users (maybe 5-10) and a modest number of daily transactions.
What is important is that we are able to upgrade the database or domain logic or interface separate from the other layers in the future.
I'm NOT looking for a buy vs. build debate, as that's a different discussion.
Thanks for any insight | Is a PHP, Python, PostgreSQL design suitable for a business application? | 0.028564 | 1 | 0 | 2,512 |
439,759 | 2009-01-13T16:47:00.000 | 1 | 0 | 0 | 0 | php,python,postgresql | 440,118 | 7 | false | 0 | 0 | I'm going to assume that by "business application" you mean a web application hosted in an intranet environment as opposed to some sort of SaaS application on the internet.
While you're in the process of architecting your application you need to consider the existing infrastructure and infrastructure support people of your employer/customer. Also, if the company is large enough to have things such as "approved software/hardware lists," you should be aware of those. Keep in mind that some elements of the list may be downright retarded. Don't let past mistakes dictate the architecture of your app, but in cases where they are reasonably sensible I would pick my battles and stick with your enterprise standard. This can be a real pain when you pick a development stack that really works best on Unix/Linux, and then someone tries to force onto a Windows server admined by someone who's never touched anything but ASP.NET applications.
Unless there is a particular PHP module that you intend to use that has no Python equivalent, I would drop PHP and use Django. If there is a compelling reason to use PHP, then I'd drop Python. I'm having difficulty imagining a scenario where you would want to use both at the same time.
As for PG versus MySQL, either works. Look at what you customer already has deployed, and if they have a bunch of one and little of another, pick that. If they have existing Oracle infrastructure you should consider using it. If they are an SQL Server shop...reconsider your stack and remember to pick your battles. | 6 | 2 | 0 | I'm looking for some quick thoughts about a business application I am looking to build. I'd like to separate the three layers of presentation, domain logic, and data using PHP, Python, and PostgreSQL, respectively. I would like to hear, possibly from other folks who have gone down this path before, if there are problems with this approach, if I am targeting the wrong tools, etc.
I'm looking at PHP because it is widely used, fairly mature, and I can find ample people with skills in PHP interface design.
I'm looking at Python because of the benefits of readable code, because I hear can find more Python programmers that also have subject-matter skills (in this case, finance), and it's an open source language. Plus, it seems easier to code with.
I'm looking at PostgreSQL for the transaction-level features. MySQL is also an option here, but I don't need to debate this aspect.
This is not a web application, although I would like to utilize a browser for the user interface. This is more of an Enterprise Application, but for a small business with moderate numbers of users (maybe 5-10) and a modest number of daily transactions.
What is important is that we are able to upgrade the database or domain logic or interface separate from the other layers in the future.
I'm NOT looking for a buy vs. build debate, as that's a different discussion.
Thanks for any insight | Is a PHP, Python, PostgreSQL design suitable for a business application? | 0.028564 | 1 | 0 | 2,512 |
439,759 | 2009-01-13T16:47:00.000 | 0 | 0 | 0 | 0 | php,python,postgresql | 440,098 | 7 | false | 0 | 0 | Just to address the MySQL vs PgSQL issues - it shouldn't matter. They're both more than capable of the task, and any reasonable framework should isolate you from the differences relatively well. I think it's down to what you use already, what people have most experience in, and if there's a feature in one or the other you think you'd benefit from.
If you have no preference, you might want to go with MySQL purely because it's more popular for web work. This translates to more examples, easier to find help, etc. I actually prefer the philosophy of PgSQL, but this isn't a good enough reason to blow against the wind. | 6 | 2 | 0 | I'm looking for some quick thoughts about a business application I am looking to build. I'd like to separate the three layers of presentation, domain logic, and data using PHP, Python, and PostgreSQL, respectively. I would like to hear, possibly from other folks who have gone down this path before, if there are problems with this approach, if I am targeting the wrong tools, etc.
I'm looking at PHP because it is widely used, fairly mature, and I can find ample people with skills in PHP interface design.
I'm looking at Python because of the benefits of readable code, because I hear can find more Python programmers that also have subject-matter skills (in this case, finance), and it's an open source language. Plus, it seems easier to code with.
I'm looking at PostgreSQL for the transaction-level features. MySQL is also an option here, but I don't need to debate this aspect.
This is not a web application, although I would like to utilize a browser for the user interface. This is more of an Enterprise Application, but for a small business with moderate numbers of users (maybe 5-10) and a modest number of daily transactions.
What is important is that we are able to upgrade the database or domain logic or interface separate from the other layers in the future.
I'm NOT looking for a buy vs. build debate, as that's a different discussion.
Thanks for any insight | Is a PHP, Python, PostgreSQL design suitable for a business application? | 0 | 1 | 0 | 2,512 |
440,036 | 2009-01-13T17:52:00.000 | 1 | 0 | 1 | 0 | java,python,ruby,multithreading,concurrency | 442,312 | 5 | false | 1 | 0 | This is not flame bait, but IMHO Java has one of the simpler and more restricted models for threading and concurrency available.
That's not necessarily a bad thing, but at the level of granularity it offers it means that the perspective it gives you of what concurrency is and how to deal with it is inherently limited if you have a "java centric" view (as someone else put it).
If you're serious about concurrency, then it's worth exploring other languages precisely because different models and idioms exist.
Some of the hottest areas are lock-free programming (you'll see a lot of it, but often done badly, in C++) and functional programming (which has been around for a while but arguably, is becoming increasingly relevant. A prime example in the case of concurrency is probably Erlang). | 3 | 7 | 0 | I am primarily a Java developer, and I've been reading a lot of in-depth work on threads and concurrency. Many very smart people (Doug Lea, Brian Goetz, etc) have authored books on these topics and made contributions to new concurrency libraries for Java.
As I start to learn more about Python, Ruby, and other languages, I'm wondering: does all of that work have to be re-created for these languages?
Will there be, or does there need to be, a "Doug Lea of Python," or a "Brian Goetz of Ruby," who make similarly powerful contributions to the concurrency features of those languages?
Does all of this concurrency work done in Java have to be re-created for future languages? Or will the work done in Java establish lessons and guidance for future languages? | Re-creating threading and concurrency knowledge in increasingly popular languages | 0.039979 | 0 | 0 | 573 |
440,036 | 2009-01-13T17:52:00.000 | 3 | 0 | 1 | 0 | java,python,ruby,multithreading,concurrency | 463,249 | 5 | false | 1 | 0 | I think the answer is both yes and no. Java arguably has the most well-defined memory model and execution semantics of the most commonly used imperative languages (Java, C++, Python, Ruby, etc). In some sense, other languages either lack this completely or are playing catch-up (if that's even possible given the immaturity of the threading models).
C++ is probably the notable exception - it has been treading the same ground for C++0x and has possibly gone beyond the current state of the Java model from my impression.
I say no because the communities are not isolated. Many of the guys working on this stuff are involved (at least from a guidance point of view, if not from a direct hand in the specs) in more than one language. So, there is a lot of crosstalk between guys working on JMM and guys working on C++0x specs as they are essentially solving the same problems with many of the same underlying drivers (from the hardware guys at the bottom and the users at the top). And I'm pretty sure there is cross-talk at some level between the JVM / CLR camps as well.
As others have mentioned, there are also other models for concurrency: actors in Erlang and Scala, agents/STM in Clojure, FP's rise in F#, Scala, Haskell, the CCR and PLINQ stuff in CLR land, etc. It's an exciting time right now! We can use as many concurrency experts as we can find I think.... :) | 3 | 7 | 0 | I am primarily a Java developer, and I've been reading a lot of in-depth work on threads and concurrency. Many very smart people (Doug Lea, Brian Goetz, etc) have authored books on these topics and made contributions to new concurrency libraries for Java.
As I start to learn more about Python, Ruby, and other languages, I'm wondering: does all of that work have to be re-created for these languages?
Will there be, or does there need to be, a "Doug Lea of Python," or a "Brian Goetz of Ruby," who make similarly powerful contributions to the concurrency features of those languages?
Does all of this concurrency work done in Java have to be re-created for future languages? Or will the work done in Java establish lessons and guidance for future languages? | Re-creating threading and concurrency knowledge in increasingly popular languages | 0.119427 | 0 | 0 | 573 |
440,036 | 2009-01-13T17:52:00.000 | 11 | 0 | 1 | 0 | java,python,ruby,multithreading,concurrency | 440,086 | 5 | false | 1 | 0 | The basic principles of concurrent programming existed before java and were summarized in those java books you're talking about. The java.util.concurrent library was similarly derived from previous code and research papers on concurrent programming.
However, some implementation issues are specific to Java. It has a specified memory model, and the concurrent utilities in Java are tailored to the specifics of that. With some modification those can be ported to other languages/environments with different memory model characteristics.
So, you might need a book to teach you the canonical usage of the concurrency tools in other languages but it wouldn't be reinventing the wheel. | 3 | 7 | 0 | I am primarily a Java developer, and I've been reading a lot of in-depth work on threads and concurrency. Many very smart people (Doug Lea, Brian Goetz, etc) have authored books on these topics and made contributions to new concurrency libraries for Java.
As I start to learn more about Python, Ruby, and other languages, I'm wondering: does all of that work have to be re-created for these languages?
Will there be, or does there need to be, a "Doug Lea of Python," or a "Brian Goetz of Ruby," who make similarly powerful contributions to the concurrency features of those languages?
Does all of this concurrency work done in Java have to be re-created for future languages? Or will the work done in Java establish lessons and guidance for future languages? | Re-creating threading and concurrency knowledge in increasingly popular languages | 1 | 0 | 0 | 573 |
440,320 | 2009-01-13T19:06:00.000 | 23 | 1 | 1 | 0 | python,unicode,utf-8 | 440,461 | 2 | false | 0 | 0 | I'd prefer 'something'.decode(...) since the unicode type is no longer there in Python 3.0, while text = b'binarydata'.decode(encoding) is still valid. | 1 | 27 | 0 | Is there any reason to prefer unicode(somestring, 'utf8') as opposed to somestring.decode('utf8')?
My only thought is that .decode() is a bound method so python may be able to resolve it more efficiently, but correct me if I'm wrong. | unicode() vs. str.decode() for a utf8 encoded byte string (python 2.x) | 1 | 0 | 0 | 30,226 |
441,256 | 2009-01-13T23:11:00.000 | 0 | 0 | 1 | 0 | python,wxpython,compilation,py2exe | 929,765 | 4 | false | 0 | 0 | I have run into similar problem few minutes ago. I couldn't run py2exe installation file, it kept saying that application configuration was incorrect. Downgrading to python 2.5 didn't work for me because I used 'with' statements through out the code and didn't want to change it.
I reinstalled python 2.6 and I checked the option that says that anyone on the computer can use python. Worked out just fine. | 2 | 5 | 0 | I've compiled my Python program using Py2Exe, and on the client's computer we've satisfied all the dependencies using dependency walker, but we still get "The application configuration is incorrect. Reinstalling the application may correct the problem." I'm also using wxPython.
The client does not have administrator access.
Any ideas? | Py2Exe - "The application configuration is incorrect." | 0 | 0 | 0 | 2,997 |
441,256 | 2009-01-13T23:11:00.000 | 1 | 0 | 1 | 0 | python,wxpython,compilation,py2exe | 441,590 | 4 | true | 0 | 0 | I've ran into this myself and my random Googling has pointed me to several people saying to downgrade python 2.6 to 2.5, which worked for me. | 2 | 5 | 0 | I've compiled my Python program using Py2Exe, and on the client's computer we've satisfied all the dependencies using dependency walker, but we still get "The application configuration is incorrect. Reinstalling the application may correct the problem." I'm also using wxPython.
The client does not have administrator access.
Any ideas? | Py2Exe - "The application configuration is incorrect." | 1.2 | 0 | 0 | 2,997 |
441,824 | 2009-01-14T03:39:00.000 | 0 | 0 | 1 | 0 | java,python,jvm | 49,241,488 | 14 | false | 0 | 0 | No, they don't both interpret byte code.
Python only interprets bytecode if you are running with pypy. Otherwise it is compiled into C and interpreted at that level.
Java compiles to bytecode. | 12 | 235 | 0 | It seems rare to read of a Python "virtual machine" while in Java "virtual machine" is used all the time.
Both interpret byte codes; why call one a virtual machine and the other an interpreter? | Java "Virtual Machine" vs. Python "Interpreter" parlance? | 0 | 0 | 0 | 72,004 |
441,824 | 2009-01-14T03:39:00.000 | 0 | 0 | 1 | 0 | java,python,jvm | 39,804,828 | 14 | false | 0 | 0 | First of all you should understand that programming or computer science in general is not mathematics and we don't have rigorous definitions for most of the terms we use often.
now to your question :
what is an Interpreter (in computer science)
It translates source code by smallest executable unit and then executes that unit.
what is a virtual machine
in case of JVM the virtual machine is a software which contains an Interpreter, class loaders, garbage collector, thread scheduler , JIT compiler and many other things.
as you can see interpreter is a part or JVM and whole JVM can not be called an interpreter because it contains many other components.
why use word "Interpreter" when talking about python
with java the compilation part is explicit.
python on the other hand is not explicit as java about its compilation and interpretation process, from end user's perspective interpretation is the only mechanism used to execute python programs | 12 | 235 | 0 | It seems rare to read of a Python "virtual machine" while in Java "virtual machine" is used all the time.
Both interpret byte codes; why call one a virtual machine and the other an interpreter? | Java "Virtual Machine" vs. Python "Interpreter" parlance? | 0 | 0 | 0 | 72,004 |
441,824 | 2009-01-14T03:39:00.000 | 14 | 0 | 1 | 0 | java,python,jvm | 53,356,426 | 14 | false | 0 | 0 | To provide a deep answer to the question "Why Java Virtual Machine, but Python interpreter?" let's try to go back to the field of compilation theory as to the starting point of the discussion.
The typical process of program compilation includes next steps:
Lexical analysis. Splits program text into meaningful "words" called tokens (as part of the process all comments, spaces, new-lines etc. are removed, because they do not affect program behavior). The result is an ordered stream of tokens.
Syntax analysis. Builds the so-called Abstract Syntax Tree (AST) from the stream of tokens. AST establish relations between tokens and, as a consequence, defines an order of evaluation of the program.
Semantic analysis. Verifies semantical correctness of the AST using information about types and a set of semantical rules of the programming language. (For example, a = b + c is a correct statement from the syntaxis point of view, but completely incorrect from the semantic point of view if a was declared as a constant object)
Intermediate code generation. Serializes AST into the linearly ordered stream of machine independent "primitive" operations. In fact, code generator traverses AST and logs the order of evaluation steps. As a result, from the tree-like representation of the program, we achieve much more simple list-like representation in which order of program evaluation is preserved.
Machine code generation. The program in the form of machine independent "primitive" bytecode is translated into machine code of particular processor architecture.
Ok. Lets now define the terms.
Interpreter, in the classical meaning of that word, assumes execution based on the program evaluation based on AST produced directly from the program text. In that case, a program is distributed in the form of source code and the interpreter is fed by program text, frequently in a dynamic way (statement-by-statement or line-by-line). For each input statement, interpreter builds its AST and immediately evaluates it changing the "state" of the program. This is a typical behavior demonstrated by scripting languages. Consider for example Bash, Windows CMD etc. Conceptually, Python takes this way too.
If we replace the AST-based execution step on the generation of intermediate machine-independent binary bytecode step in the interpreter we will split the entire process of program execution into two separate phases: compilation and execution. In that case what previously was an interpreter will become a bytecode compiler, which will transform the program from the form of the text into some binary form. Then the program is distributed in that binary form, but not in the form of source code. On the user machine, that bytecode is fed into a new entity -- virtual machine, which in fact interpret that bytecode. Due to this, virtual machines are also called bytecode interpreter. But put your attention here! A classical interpreter is a text interpreter, but a virtual machine is a binary interpreter! This is an approach taken by Java and C#.
Finally, if we add the machine code generation to the bytecode compiler we achieve in result what we call a classical compiler. A classical compiler converts the program source code into the machine code of a particular processor. That machine code then can be directly executed on the target processor without any additional mediation (without any kind of interpreter neither text interpreter nor binary interpreter).
Lets now go back to the original question and consider Java vs Python.
Java was initially designed to have as few implementation dependencies as possible. Its design is based on the principle "write once, run anywhere" (WORA). To implement it, Java was initially designed as a programming language that compiles into machine-independent binary bytecode, which then can be executed on all platforms that support Java without the need for its recompilation. You can think about Java like about WORA-based C++. Actually, Java is closer to C++ than to the scripting languages like Python. But in contrast to C++, Java was designed to be compiled into binary bytecode which then is executed in the environment of the virtual machine, while C++ was designed to be compiled in machine code and then directly executed by the target processor.
Python was initially designed as a kind of scripting programing language which interprets scripts (programs in the form of the text written in accordance with the programming language rules). Due to this, Python has initially supported a dynamic interpretation of one-line commands or statements, as the Bash or Windows CMD do. For the same reason, initial implementations of Python had not any kind of bytecode compilers and virtual machines for execution of such bytecode inside, but from the start Python had required interpreter which is capable to understand and evaluate Python program text.
Due to this, historically, Java developers tended to talk about Java Virtual Machine (because initially, Java has come as package of Java bytecode compiler and bytecode interpreter -- JVM), and Python developers tended to talk about Python interpreter (because initially Python has not any virtual machine and was a kind of classical text interpreter that executes program text directly without any sort of compilation or transformation into any form of binary code).
Currently, Python also has the virtual machine under the hood and can compile and interpret Python bytecode. And that fact makes an additional investment into the confusion "Why Java Virtual Machine, but Python interpreter?", because it seems that implementations of both languages contain virtual machines.
But! Even in the current moment interpretation of program text is a primary way of Python programs execution. Python implementations exploit virtual machines under the hood exclusively as an optimization technique. Interpretation of binary bytecode in the virtual machine is much more efficient than a direct interpretation of the original program text. At the same time, the presence of the virtual machine in the Python is absolutely transparent for both Python language designers and Python programs developers. The same language can be implemented in interpreters with and without the virtual machine. In the same way, the same programs can be executed in interpreters with and without the virtual machine, and that programs will demonstrate exactly the same behavior and produce equally the same output from the equal input. The only observable difference will be the speed of program execution and the amount of memory consumed by the interpreter. Thus, the virtual machine in Python is not an unavoidable part of the language design, but just an optional extension of the major Python interpreter.
Java can be considered in a similar way. Java under the hood has a JIT compiler and can selectively compile methods of Java class into machine code of the target platform and then directly execute it. But! Java still uses bytecode interpretation as a primary way of Java program execution. Like Python implementations which exploit virtual machines under the hood exclusively as an optimization technique, the Java virtual machines use Just-In-Time compilers exclusively for optimization purposes. Similarly, just because of the fact that direct execution of the machine code at least ten times faster than the interpretation of Java bytecode. And like in the case of Python, the presence of JIT compiler under the hood of JVM is absolutely transparent for both Java language designers and Java program developers. The same Java programming language can be implemented by JVM with and without JIT compiler. And in the same way, the same programs can be executed in JVMs with and without JIT inside, and the same programs will demonstrate exactly the same behavior and produce equally the same output from the equal input on both JVMs (with and without JIT). And like in the case of Python, the only observable difference between them, will be in the speed of execution and in the amount of memory consumed by JVM. And finally, like in the case of Python, JIT in Java also is not an unavoidable part of the language design, but just an optional extension of the major JVM implementations.
From the point of view of design and implementation of virtual machines of Java and Python, they differ significantly, while (attention!) both still stay virtual machines. JVM is an example of a low-level virtual machine with simple basic operations and high instruction dispatch cost. Python in its turn is a high-level virtual machine, for which instructions demonstrate complex behavior, and instruction dispatch cost is not so significant. Java operates with very low abstraction level. JVM operates on the small well-defined set of primitive types and has very tight correspondence (typically one to one) between bytecode instructions and native machine code instructions. In contrary, Python virtual machine operates at high abstraction level, it operates with complex data types (objects) and supports ad-hoc polymorphism, while bytecode instructions expose complex behavior, which can be represented by a series of multiple native machine code instructions. For example, Python supports unbounded range mathematics. Thus Python VM is forced to exploit long arithmetics for potentially big integers for which result of the operation can overflow the machine word. Hence, one bytecode instruction for arithmetics in Python can expose into the function call inside Python VM, while in JVM arithmetic operation will expose into simple operation expressed by one or few native machine instructions.
As a result, we can draw the next conclusions. Java Virtual Machine but Python interpreter is because:
The term of virtual machine assumes binary bytecode interpretation, while the term interpreter assumes program text interpretation.
Historically, Java was designed and implemented for binary bytecode interpretation and Python was initially designed and implemented for program text interpretation. Thus, the term "Java Virtual Machine" is historical and well established in the Java community. And similarly, the term "Python Interpreter" is historical and well established in the Python community. Peoples tend to prolong the tradition and use the same terms that were used long before.
Finally, currently, for Java, binary bytecode interpretation is a primary way of programs execution, while JIT-compilation is just an optional and transparent optimization. And for Python, currently, program text interpretation is a primary way of Python programs execution, while compilation into Python VM bytecode is just an optional and transparent optimization.
Therefore, both Java and Python have virtual machines are binary bytecode interpreters, which can lead to confusion such as "Why Java Virtual Machine, but Python interpreter?". The key point here is that for Python, a virtual machine is not a primary or necessary means of program execution; it is just an optional extension of the classical text interpreter. On the other hand, a virtual machine is a core and unavoidable part of Java program execution ecosystem. Static or dynamic typing choice for the programming language design affects mainly the virtual machine abstraction level only, but does not dictate whether or not a virtual machine is needed. Languages using both typing systems can be designed to be compiled, interpreted, or executed within the environment of virtual machine, depending on their desired execution model. | 12 | 235 | 0 | It seems rare to read of a Python "virtual machine" while in Java "virtual machine" is used all the time.
Both interpret byte codes; why call one a virtual machine and the other an interpreter? | Java "Virtual Machine" vs. Python "Interpreter" parlance? | 1 | 0 | 0 | 72,004 |
441,824 | 2009-01-14T03:39:00.000 | 144 | 0 | 1 | 0 | java,python,jvm | 441,973 | 14 | true | 0 | 0 | A virtual machine is a virtual computing environment with a specific set of atomic well defined instructions that are supported independent of any specific language and it is generally thought of as a sandbox unto itself. The VM is analogous to an instruction set of a specific CPU and tends to work at a more fundamental level with very basic building blocks of such instructions (or byte codes) that are independent of the next. An instruction executes deterministically based only on the current state of the virtual machine and does not depend on information elsewhere in the instruction stream at that point in time.
An interpreter on the other hand is more sophisticated in that it is tailored to parse a stream of some syntax that is of a specific language and of a specific grammer that must be decoded in the context of the surrounding tokens. You can't look at each byte or even each line in isolation and know exactly what to do next. The tokens in the language can't be taken in isolation like they can relative to the instructions (byte codes) of a VM.
A Java compiler converts Java language into a byte-code stream no different than a C compiler converts C Language programs into assembly code. An interpreter on the other hand doesn't really convert the program into any well defined intermediate form, it just takes the program actions as a matter of the process of interpreting the source.
Another test of the difference between a VM and an interpreter is whether you think of it as being language independent. What we know as the Java VM is not really Java specific. You could make a compiler from other languages that result in byte codes that can be run on the JVM. On the other hand, I don't think we would really think of "compiling" some other language other than Python into Python for interpretation by the Python interpreter.
Because of the sophistication of the interpretation process, this can be a relatively slow process....specifically parsing and identifying the language tokens, etc. and understanding the context of the source to be able to undertake the execution process within the interpreter. To help accelerate such interpreted languages, this is where we can define intermediate forms of pre-parsed, pre-tokenized source code that is more readily directly interpreted. This sort of binary form is still interpreted at execution time, it is just starting from a much less human readable form to improve performance. However, the logic executing that form is not a virtual machine, because those codes still can't be taken in isolation - the context of the surrounding tokens still matter, they are just now in a different more computer efficient form. | 12 | 235 | 0 | It seems rare to read of a Python "virtual machine" while in Java "virtual machine" is used all the time.
Both interpret byte codes; why call one a virtual machine and the other an interpreter? | Java "Virtual Machine" vs. Python "Interpreter" parlance? | 1.2 | 0 | 0 | 72,004 |
441,824 | 2009-01-14T03:39:00.000 | 12 | 0 | 1 | 0 | java,python,jvm | 441,901 | 14 | false | 0 | 0 | The term interpreter is a legacy term dating back to earlier shell scripting languages. As "scripting languages" have evolved into full featured languages and their corresponding platforms have become more sophisticated and sandboxed, the distinction between a virtual machine and an interpreter (in the Python sense), is very small or non-existent.
The Python interpreter still functions in the same way as a shell script, in the sense that it can be executed without a separate compile step. Beyond that, the differences between Python's interpreter (or Perl or Ruby's) and Java's virtual machine are mostly implementation details. (One could argue that Java is more fully sandboxed than Python, but both ultimately provide access to the underlying architecture via a native C interface.) | 12 | 235 | 0 | It seems rare to read of a Python "virtual machine" while in Java "virtual machine" is used all the time.
Both interpret byte codes; why call one a virtual machine and the other an interpreter? | Java "Virtual Machine" vs. Python "Interpreter" parlance? | 1 | 0 | 0 | 72,004 |
441,824 | 2009-01-14T03:39:00.000 | 68 | 0 | 1 | 0 | java,python,jvm | 441,854 | 14 | false | 0 | 0 | Probably one reason for the different terminology is that one normally thinks of feeding the python interpreter raw human-readable source code and not worrying about bytecode and all that.
In Java, you have to explicitly compile to bytecode and then run just the bytecode, not source code on the VM.
Even though Python uses a virtual machine under the covers, from a user's perspective, one can ignore this detail most of the time. | 12 | 235 | 0 | It seems rare to read of a Python "virtual machine" while in Java "virtual machine" is used all the time.
Both interpret byte codes; why call one a virtual machine and the other an interpreter? | Java "Virtual Machine" vs. Python "Interpreter" parlance? | 1 | 0 | 0 | 72,004 |
441,824 | 2009-01-14T03:39:00.000 | 11 | 0 | 1 | 0 | java,python,jvm | 441,830 | 14 | false | 0 | 0 | There's no real difference between them, people just follow the conventions the creators have chosen. | 12 | 235 | 0 | It seems rare to read of a Python "virtual machine" while in Java "virtual machine" is used all the time.
Both interpret byte codes; why call one a virtual machine and the other an interpreter? | Java "Virtual Machine" vs. Python "Interpreter" parlance? | 1 | 0 | 0 | 72,004 |
441,824 | 2009-01-14T03:39:00.000 | 3 | 0 | 1 | 0 | java,python,jvm | 57,942,833 | 14 | false | 0 | 0 | Python can interpret code without compiling it to bytecode. Java can't.
Python is an interpreted language, as opposed to a compiled one, though the distinction can be blurry because of the presence of the bytecode compiler. This means that source files can be run directly without explicitly creating an executable which is then run.
(from the documentation).
In java, every single file has to be compiled to a .class file, which then runs on the JVM. On the contrary, python does that are imported by your main script, to help speed up subsequent uses of those files.
However, in the typical case, most of the python (at least, CPython) code runs in an emulated stack machine, which has nearly identical instructions to those of the JVM, so there's no great difference.
The real reason for the distiction however is because, from the beginning, java branded itself as "portable, executable bytecode" and python branded itself as dynamic, interpreted language with a REPL. Names stick! | 12 | 235 | 0 | It seems rare to read of a Python "virtual machine" while in Java "virtual machine" is used all the time.
Both interpret byte codes; why call one a virtual machine and the other an interpreter? | Java "Virtual Machine" vs. Python "Interpreter" parlance? | 0.042831 | 0 | 0 | 72,004 |
441,824 | 2009-01-14T03:39:00.000 | 3 | 0 | 1 | 0 | java,python,jvm | 441,926 | 14 | false | 0 | 0 | Don't forget that Python has JIT compilers available for x86, further confusing the issue. (See psyco).
A more strict interpretation of an 'interpreted language' only becomes useful when discussing performance issues of the VM, for example, compared with Python, Ruby was (is?) considered to be slower because it is an interpreted language, unlike Python - in other words, context is everything. | 12 | 235 | 0 | It seems rare to read of a Python "virtual machine" while in Java "virtual machine" is used all the time.
Both interpret byte codes; why call one a virtual machine and the other an interpreter? | Java "Virtual Machine" vs. Python "Interpreter" parlance? | 0.042831 | 0 | 0 | 72,004 |
441,824 | 2009-01-14T03:39:00.000 | 0 | 0 | 1 | 0 | java,python,jvm | 66,917,426 | 14 | false | 0 | 0 | There actually might be a reason why the HotSpot runtime is called a Virtual Machine while CPython is merely referred to as an interpreter
Firstly, CPython is just your average run of the mill, stack based, bytecode interpreter. You input Python opcode into it, and the software stack machine inside CPython evaluates your code, just like a normal Interpreter would.
The Java HotSpot runtime is different. First and foremost, Java has 3 Just-in Time Compilers, C1, C2, and an experimental one that isn't in use yet. But that's not the main reason. The Interpreter inside the JVM is a very special kind of Interpreter called a Template Interpreter. Instead of just executing bytecode directly in a massive opcode switch case statement like CPython (And really almost every other interpreter does) does, the Template Interpreter inside the JVM contains an enormous arraylist. What does it contain? Key-value pairs of bytecodes and native CPU instructions! The arraylist is empty on startup and is filled with mappings of bytecodes pointing to native machine language to be directly run on the hardware just before your application starts up, what this means is that the "Interpreter" inside the JVM isn't actually an Interpreter at all- It's actually a discount Compiler! When Java bytecode is run, the "Interpreter" simply maps the input bytecode directly to native machine language and executes the native mapping directly, rather than implementing it in software. I'm not exactly sure why the JVM was made this way, but I suspect it was to easily execute "Interpreted" Code together with JIT Compiled Code seamlessly, and for speed/performance. If you pitted the JVM without JIT against CPython or most other interpreters it would still probably come out ahead of them, in virtue of its ingenious design which to my knowledge no other language has used before. | 12 | 235 | 0 | It seems rare to read of a Python "virtual machine" while in Java "virtual machine" is used all the time.
Both interpret byte codes; why call one a virtual machine and the other an interpreter? | Java "Virtual Machine" vs. Python "Interpreter" parlance? | 0 | 0 | 0 | 72,004 |
441,824 | 2009-01-14T03:39:00.000 | 0 | 0 | 1 | 0 | java,python,jvm | 59,725,809 | 14 | false | 0 | 0 | for posts that mention that python does not need to generate byte code, I'm not sure that's true. it seems that all callables in Python must have a .__code__.co_code attribute which contains the byte code. I don't see a meaningful reason to call python "not compiled" just because the compiled artifacts may not be saved; and often aren't saved by design in Python, for example all comprehension compile new bytecode for it's input, this is the reason comprehension variable scope is not consistent between compile(mode='exec, ...) and compile compile(mode='single', ...) such as between running a python script and using pdb | 12 | 235 | 0 | It seems rare to read of a Python "virtual machine" while in Java "virtual machine" is used all the time.
Both interpret byte codes; why call one a virtual machine and the other an interpreter? | Java "Virtual Machine" vs. Python "Interpreter" parlance? | 0 | 0 | 0 | 72,004 |
441,824 | 2009-01-14T03:39:00.000 | 1 | 0 | 1 | 0 | java,python,jvm | 58,199,884 | 14 | false | 0 | 0 | I think the lines between both are blurred, people mostly argue around meaning of word "interpreter" and how close the language stands to each side of "interpreter...compiler" spectrum. None makes 100% however. I think it is easy to write Java or Python implementation which be of any value of the spectrum.
Currently both Java and Python have virtual machines and bytecode, though one operates by concrete value sizes (like 32-bit integer) while other has to determine the size for each call, which in my opinion doesn't define the border between the terms.
The argument that Python doesn't have officially defined bytecode and it exists only in memory also doesn't convince me, just because I am planning to develop devices which will recognize only Python bytecode and the compilation part will be done in browser JS machine.
Performance is only about the concrete implementation. We don't need to know the size of the object to be able to work with it, and finally, in most cases, we work with structures, not basic types. It is possible to optimize Python VM in the way that it will eliminate the need of creating new object each time during expression calculation, by reusing existing one. Once it is done, there is no global performance difference between calculating sum of two integers, which is where Java shines.
There is no killer difference between the two, only some implementation nuances and lack of optimization which are irrelevant to the end user, maybe up at the point where she starts to notice performance lags, but again it is implementation and not architecture issue. | 12 | 235 | 0 | It seems rare to read of a Python "virtual machine" while in Java "virtual machine" is used all the time.
Both interpret byte codes; why call one a virtual machine and the other an interpreter? | Java "Virtual Machine" vs. Python "Interpreter" parlance? | 0.014285 | 0 | 0 | 72,004 |
441,849 | 2009-01-14T03:51:00.000 | 1 | 0 | 0 | 1 | python,networking,twisted | 442,079 | 5 | false | 0 | 0 | Just adding an answer to re-iterate other posters - it'll be worth it to use Twisted. There's no reason to write yet another TCP server that'll end up working not as well as one using twisted would. The only reason would be if writing your own is much faster, developer-wise, but if you just bite the bullet and learn twisted now, your future projects will benefit greatly. And, as others have said, you'll be able to do much more complex stuff if you use twisted from the start. | 2 | 12 | 0 | I was just wondering what network libraries there are out there for Python for building a TCP/IP server. I know that Twisted might jump to mind but the documentation seems scarce, sloppy, and scattered to me.
Also, would using Twisted even have a benefit over rolling my own server with select.select()? | Good Python networking libraries for building a TCP server? | 0.039979 | 0 | 1 | 12,949 |
441,849 | 2009-01-14T03:51:00.000 | 6 | 0 | 0 | 1 | python,networking,twisted | 441,863 | 5 | false | 0 | 0 | The standard library includes SocketServer and related modules which might be sufficient for your needs. This is a good middle ground between a complex framework like Twisted, and rolling your own select() loop. | 2 | 12 | 0 | I was just wondering what network libraries there are out there for Python for building a TCP/IP server. I know that Twisted might jump to mind but the documentation seems scarce, sloppy, and scattered to me.
Also, would using Twisted even have a benefit over rolling my own server with select.select()? | Good Python networking libraries for building a TCP server? | 1 | 0 | 1 | 12,949 |
442,188 | 2009-01-14T07:34:00.000 | 0 | 0 | 1 | 0 | python | 442,662 | 4 | false | 0 | 0 | Note that Python doesn't have readByte, readInt and readString because it doesn't work directly with all those fancy data types. Files provides strings which you can convert.
Python <= 2.6 has String and that's what you get from your input streams -- strings. The simple socket.read() provides this input. You can use struct to convert the stream into a sequence of integers. What's important is that the pack and unpack conversions may be by byte, word, long, or whatever, but the Python result is integers.
So your input may be bytes, but Python represents this as a string, much of which is unprintable. Your desire may be an array of individual values, each between 0 and 255, that are the numeric versions of those bytes. Python represents these as integers.
Python >= 3.0 has bytearrays that can be used to process bytes directly. You'll can convert them to strings, or integers (which include bytes and longs) or whatever. | 1 | 6 | 0 | The functions ReadInt(), ReadByte(), and ReadString() (to name a few) exist in other languages for reading input from streams. I am trying to read from a socket, and I want to use functions like these. Are they tucked away in Python somewhere under a different way or has someone made a library for it?
Also, there are Writedatatype() counterparts. | ReadInt(), ReadByte(), ReadString(), etc. in Python? | 0 | 0 | 0 | 14,799 |
442,355 | 2009-01-14T09:11:00.000 | 0 | 0 | 0 | 0 | python,django,configuration,django-models,django-admin | 448,110 | 3 | false | 1 | 0 | I think you'll have trouble if you make other apps depend (at interpretation/app-loading time) on values set in your config app. Can you use some kind of placeholder value in Python code at interpretation time, and then pull in the real config data on the post_syncdb signal? | 1 | 4 | 0 | I need to program kind of configuration registry for Django-based application.
Requirements:
Most likely param_name : param_value structure
Editable via admin interface
Has to work with syncdb. How to deal with a situation in which other apps depend on configuration model and the model itself has not been initialized yet in DB? Let's say I would like to have configurable model fields properties, i.e. the default value setting?
Any ideas or suggestions would be appreciated. | What is the best approach to implement configuration app with Django? | 0 | 0 | 0 | 1,916 |
442,596 | 2009-01-14T11:04:00.000 | 1 | 0 | 0 | 0 | python,django | 443,155 | 2 | false | 1 | 0 | I would also suggest considering getting a mapping of all data once instead of requesting subfield values one by one. Unless the subfield choices change frequently (states/cities change?) or huge in numbers (>1000) this should offer best performance and it is less complex.
You don't even need to create a seperate view, just include a chunk of JavaScript (a JSON mapping more precisely) with your response containing the form. | 1 | 3 | 0 | Can anyone point to an example written in Python (django preferred) with ajax for cascading forms? Cascading Forms is basically forms whose field values change if and when another field value changes. Example Choose Country, and then States will change... | cascading forms in Django/else using any Pythonic framework | 0.099668 | 0 | 0 | 612 |
443,082 | 2009-01-14T14:17:00.000 | 0 | 0 | 1 | 0 | python,multithreading | 661,707 | 2 | false | 0 | 0 | Thank you for this answer! Actually I am running one profiler in each context, so the question make sense. From the tests I made the profiler would measure "linef1 linef2 linef3" in the above example. | 1 | 1 | 0 | This is a question about Python native c file _lsprof.
How does _lsprof.profile() profiler counts total time spent on a function f in a multi-threaded program if the execution of f is interrupted by another thread?
For example:
def f():
linef1
linef2
linef3
def g():
lineg1
lineg2
And at the execution we have, f and g not being in the same thread:
linef1
linef2
lineg1
linef3
lineg2
Then will the total runtime of f be perceived as the amount of time needed to do:
linef1
linef2
linef3
or will it be the effective latency time:
linef1
linef2
lineg1
linef3
in the results of _lsprof.profile()? | _lsprof.c profiler behaviour towards python multi-threading | 0 | 0 | 0 | 259 |
443,885 | 2009-01-14T17:20:00.000 | 0 | 1 | 1 | 0 | python,events,delegates,callback | 443,934 | 8 | false | 0 | 0 | Personally, I've only seen callbacks used. However, I haven't seen that much event driven python code so YMMV. | 2 | 25 | 0 | Just want to know what's the common way to react on events in python. There are several ways in other languages like callback functions, delegates, listener-structures and so on.
Is there a common way? Which default language concepts or additional modules are there and which can you recommend? | Python: Callbacks, Delegates, ... ? What is common? | 0 | 0 | 0 | 23,479 |
443,885 | 2009-01-14T17:20:00.000 | 0 | 1 | 1 | 0 | python,events,delegates,callback | 444,003 | 8 | false | 0 | 0 | I have seen listeners and callbacks used. But AFAIK there is no Python way. They should be equally feasible if the application in question is suitable. | 2 | 25 | 0 | Just want to know what's the common way to react on events in python. There are several ways in other languages like callback functions, delegates, listener-structures and so on.
Is there a common way? Which default language concepts or additional modules are there and which can you recommend? | Python: Callbacks, Delegates, ... ? What is common? | 0 | 0 | 0 | 23,479 |
443,996 | 2009-01-14T17:49:00.000 | 0 | 1 | 0 | 0 | ironpython,ironruby | 592,844 | 3 | false | 1 | 0 | We're looking at attribute support again for a .NET interop-focused release in the near future. Keep an eye on [email protected] for an updates. | 1 | 1 | 0 | I have scanned 'the Google' and have not found the definitive answer on whether the Iron* languages (any or all) will end up with Attribute support..
Anyone?
Thanks - Jon | Has anyone tracked down whether IronPython or IronRuby will support Attributes? | 0 | 0 | 0 | 316 |
444,509 | 2009-01-14T20:17:00.000 | 6 | 0 | 1 | 0 | python,debugging,interactive | 444,918 | 5 | false | 0 | 0 | You could try looking at the python debugger pdb. It's like gdb in how you use it, but implemented in pure python. Have a look for pdb.py in your python install directory. | 1 | 11 | 0 | I've seen a couple of Python IDE's (e.g. PyDev Extensions, WingIDE) that provide a debug console - an interactive terminal that runs in the context of the method where the breakpoint is. This lets you print members, call other methods and see the results, and redefine methods to try to fix bugs. Cool.
Can anyone tell me how this is implemented? I know there's the Code module, which provides an InteractiveConsole class, but I don't know how this can be run in the context of currently loaded code. I'm quite new to Python, so gentle assistance would be appreciated! | How are debug consoles implemented in Python? | 1 | 0 | 0 | 1,515 |
445,037 | 2009-01-14T22:57:00.000 | 2 | 0 | 0 | 0 | python,user-interface,wxpython,wxwidgets,toolbar | 446,014 | 3 | false | 0 | 1 | Doesn't the size of the toolbar adapts itself automatically to the size of the bitmap icons? I think if you want a bigger toolbar, you need bigger bitmaps. | 1 | 2 | 0 | I've got a wx.Toolbar and I'd like to make the buttons larger. I've searched and can't seem to find any concrete documentation on how to do this.
I'm also wondering how well this will translate across platforms; what will happen to the buttons and icons on OSX? | How to make a wx Toolbar buttons larger? | 0.132549 | 0 | 0 | 3,854 |
445,595 | 2009-01-15T04:01:00.000 | 3 | 0 | 1 | 1 | python,windows,python-idle | 445,607 | 9 | false | 0 | 0 | However, I want to run programs in
some other shell than the crappy
windows command prompt, which can't be
widened to more than 80 characters.
Click on the system box (top-left) in the command prompt and click properties. In the layout tab you can set the width and height of the window and the width and height of the screen buffer. I recommend setting the screen buffer height to 9999 so you can scroll back through a long output. | 3 | 24 | 0 | Python for Windows by default comes with IDLE, which is the barest-bones IDE I've ever encountered. For editing files, I'll stick to emacs, thank you very much.
However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters.
IDLE lets me run programs in it if I open the file, then hit F5 (to go Run-> Run Module). I would rather like to just "run" the command, rather than going through the rigmarole of closing the emacs file, loading the IDLE file, etc. A scan of google and the IDLE docs doesn't seem to give much help about using IDLE's shell but not it's IDE.
Any advice from the stack overflow guys? Ideally I'd either like
advice on running programs using IDLE's shell
advice on other ways to run python programs in windows outside of IDLE or "cmd".
Thanks,
/YGA | Cleanest way to run/debug python programs in windows | 0.066568 | 0 | 0 | 35,429 |
445,595 | 2009-01-15T04:01:00.000 | 0 | 0 | 1 | 1 | python,windows,python-idle | 679,859 | 9 | false | 0 | 0 | I replaced cmd with Cygwin and Poderosa. May be a little overkill though, if the only problem you have with cmd is that it's a pain to resize.
Although you use Emacs instead of Vim, so I guess you're into overkill... ;-) | 3 | 24 | 0 | Python for Windows by default comes with IDLE, which is the barest-bones IDE I've ever encountered. For editing files, I'll stick to emacs, thank you very much.
However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters.
IDLE lets me run programs in it if I open the file, then hit F5 (to go Run-> Run Module). I would rather like to just "run" the command, rather than going through the rigmarole of closing the emacs file, loading the IDLE file, etc. A scan of google and the IDLE docs doesn't seem to give much help about using IDLE's shell but not it's IDE.
Any advice from the stack overflow guys? Ideally I'd either like
advice on running programs using IDLE's shell
advice on other ways to run python programs in windows outside of IDLE or "cmd".
Thanks,
/YGA | Cleanest way to run/debug python programs in windows | 0 | 0 | 0 | 35,429 |
445,595 | 2009-01-15T04:01:00.000 | 9 | 0 | 1 | 1 | python,windows,python-idle | 445,618 | 9 | false | 0 | 0 | You can easily widen the Windows console by doing the following:
click the icon for the console window in the upper right
select Properties from the menu
click the Layout tab
change the Window Size > Width to 140
This can also be saved universally by changing the Defaults on the menu. | 3 | 24 | 0 | Python for Windows by default comes with IDLE, which is the barest-bones IDE I've ever encountered. For editing files, I'll stick to emacs, thank you very much.
However, I want to run programs in some other shell than the crappy windows command prompt, which can't be widened to more than 80 characters.
IDLE lets me run programs in it if I open the file, then hit F5 (to go Run-> Run Module). I would rather like to just "run" the command, rather than going through the rigmarole of closing the emacs file, loading the IDLE file, etc. A scan of google and the IDLE docs doesn't seem to give much help about using IDLE's shell but not it's IDE.
Any advice from the stack overflow guys? Ideally I'd either like
advice on running programs using IDLE's shell
advice on other ways to run python programs in windows outside of IDLE or "cmd".
Thanks,
/YGA | Cleanest way to run/debug python programs in windows | 1 | 0 | 0 | 35,429 |
445,827 | 2009-01-15T06:07:00.000 | 13 | 0 | 0 | 1 | python,google-app-engine,join,google-cloud-datastore | 446,471 | 4 | false | 1 | 0 | If you look at how the SQL solution you provided will be executed, it will go basically like this:
Fetch a list of friends for the current user
For each user in the list, start an index scan over recent posts
Merge-join all the scans from step 2, stopping when you've retrieved enough entries
You can carry out exactly the same procedure yourself in App Engine, by using the Query instances as iterators and doing a merge join over them.
You're right that this will not scale well to large numbers of friends, but it suffers from exactly the same issues the SQL implementation has, it just doesn't disguise them as well: Fetching the latest 20 (for example) entries costs roughly O(n log n) work, where n is the number of friends. | 2 | 13 | 0 | Example Problem:
Entities:
User contains name and a list of friends (User references)
Blog Post contains title, content, date and Writer (User)
Requirement:
I want a page that displays the title and a link to the blog of the last 10 posts by a user's friend. I would also like the ability to keep paging back through older entries.
SQL Solution:
So in sql land it would be something like:
select * from blog_post where user_id in (select friend_id from user_friend where user_id = :userId) order by date
GAE solutions i can think of are:
Load user, loop through the list of friends and load their latest blog posts. Finally merge all the blog posts to find the latest 10 blog entries
In a blog post have a list of all users that have the writer as a friend. This would mean a simple read but would result in quota overload when adding a friend who has lots of blog posts.
I don't believe either of these solutions will scale.
Im sure others have hit this problem but I've searched, watched google io videos, read other's code ... What am i missing? | GAE - How to live with no joins? | 1 | 1 | 0 | 2,112 |
445,827 | 2009-01-15T06:07:00.000 | 1 | 0 | 0 | 1 | python,google-app-engine,join,google-cloud-datastore | 446,477 | 4 | false | 1 | 0 | "Load user, loop through the list of friends and load their latest blog posts."
That's all a join is -- nested loops. Some kinds of joins are loops with lookups. Most lookups are just loops; some are hashes.
"Finally merge all the blog posts to find the latest 10 blog entries"
That's a ORDER BY with a LIMIT. That's what the database is doing for you.
I'm not sure what's not scalable about this; it's what a database does anyway. | 2 | 13 | 0 | Example Problem:
Entities:
User contains name and a list of friends (User references)
Blog Post contains title, content, date and Writer (User)
Requirement:
I want a page that displays the title and a link to the blog of the last 10 posts by a user's friend. I would also like the ability to keep paging back through older entries.
SQL Solution:
So in sql land it would be something like:
select * from blog_post where user_id in (select friend_id from user_friend where user_id = :userId) order by date
GAE solutions i can think of are:
Load user, loop through the list of friends and load their latest blog posts. Finally merge all the blog posts to find the latest 10 blog entries
In a blog post have a list of all users that have the writer as a friend. This would mean a simple read but would result in quota overload when adding a friend who has lots of blog posts.
I don't believe either of these solutions will scale.
Im sure others have hit this problem but I've searched, watched google io videos, read other's code ... What am i missing? | GAE - How to live with no joins? | 0.049958 | 1 | 0 | 2,112 |
446,685 | 2009-01-15T13:21:00.000 | 0 | 0 | 1 | 0 | python,ruby,perl | 447,176 | 9 | false | 0 | 0 | "installing Perl on Windows would not be worth it for them" Really? It's that complex?
Python has a simple .MSI that neatly installs itself with no muss or fuss.
A simple application program is just a few .py files, so, I don't see a big pain factor there.
You know your customers best.
I find that the following isn't so bad. And it's much easier to support, since your upgrades will just be a single .MSI with simple, easy-to-live with source.
1) double click this .MSI file to install Python (or Perl or whatever)
2) double click this other .MSI to install the good stuff | 1 | 22 | 0 | I want to write a piece of software which is essentially a regex data scrubber. I am going to take a contact list in CSV and remove all non-word characters and such from the person's name.
This project has Perl written all over it but my client base is largely non-technical and installing Perl on Windows would not be worth it for them.
Any ideas on how I can use a Perl/Python/Ruby type language without all the headaches of getting the interpreter on their computer?
Thought about web for a second but it would not work for business reasons. | How can I deploy a Perl/Python/Ruby script without installing an interpreter? | 0 | 0 | 0 | 11,996 |
446,782 | 2009-01-15T13:48:00.000 | 3 | 0 | 1 | 0 | python,exception,function | 446,817 | 5 | false | 0 | 0 | Assuming you want to "stop" execution inside of that method. There's a few things you can do.
Don't catch the exception. This will return control to the method that called it in the first place. You can then do whatever you want with it.
sys.exit(0) This one actually exits the entire program.
return I know you said you don't want return, but hear me out. Return is useful, because based on the value you return, it would be a good way to let your users know what went wrong. | 2 | 11 | 0 | I want to get out of a function when an exception occurs or so.
I want to use other method than 'return' | Getting out of a function in Python | 0.119427 | 0 | 0 | 56,237 |
446,782 | 2009-01-15T13:48:00.000 | 4 | 0 | 1 | 0 | python,exception,function | 446,805 | 5 | false | 0 | 0 | Can't think of another way to "get out" of a function other than a) return, b) throw an exception, or c) terminate execution of the program. | 2 | 11 | 0 | I want to get out of a function when an exception occurs or so.
I want to use other method than 'return' | Getting out of a function in Python | 0.158649 | 0 | 0 | 56,237 |
447,107 | 2009-01-15T15:13:00.000 | 12 | 0 | 1 | 0 | python,string,unicode,character-encoding,python-2.x | 447,401 | 6 | false | 0 | 0 | mybytestring.encode(somecodec) is meaningful for these values of somecodec:
base64
bz2
zlib
hex
quopri
rot13
string_escape
uu
I am not sure what decoding an already decoded unicode text is good for. Trying that with any encoding seems to always try to encode with the system's default encoding first. | 3 | 185 | 0 | I've never been sure that I understand the difference between str/unicode decode and encode.
I know that str().decode() is for when you have a string of bytes that you know has a certain character encoding, given that encoding name it will return a unicode string.
I know that unicode().encode() converts unicode chars into a string of bytes according to a given encoding name.
But I don't understand what str().encode() and unicode().decode() are for. Can anyone explain, and possibly also correct anything else I've gotten wrong above?
EDIT:
Several answers give info on what .encode does on a string, but no-one seems to know what .decode does for unicode. | What is the difference between encode/decode? | 1 | 0 | 0 | 111,429 |
447,107 | 2009-01-15T15:13:00.000 | 16 | 0 | 1 | 0 | python,string,unicode,character-encoding,python-2.x | 452,378 | 6 | false | 0 | 0 | anUnicode.encode('encoding') results in a string object and can be called on a unicode object
aString.decode('encoding') results in an unicode object and can be called on a string, encoded in given encoding.
Some more explanations:
You can create some unicode object, which doesn't have any encoding set. The way it is stored by Python in memory is none of your concern. You can search it, split it and call any string manipulating function you like.
But there comes a time, when you'd like to print your unicode object to console or into some text file. So you have to encode it (for example - in UTF-8), you call encode('utf-8') and you get a string with '\u<someNumber>' inside, which is perfectly printable.
Then, again - you'd like to do the opposite - read string encoded in UTF-8 and treat it as an Unicode, so the \u360 would be one character, not 5. Then you decode a string (with selected encoding) and get brand new object of the unicode type.
Just as a side note - you can select some pervert encoding, like 'zip', 'base64', 'rot' and some of them will convert from string to string, but I believe the most common case is one that involves UTF-8/UTF-16 and string. | 3 | 185 | 0 | I've never been sure that I understand the difference between str/unicode decode and encode.
I know that str().decode() is for when you have a string of bytes that you know has a certain character encoding, given that encoding name it will return a unicode string.
I know that unicode().encode() converts unicode chars into a string of bytes according to a given encoding name.
But I don't understand what str().encode() and unicode().decode() are for. Can anyone explain, and possibly also correct anything else I've gotten wrong above?
EDIT:
Several answers give info on what .encode does on a string, but no-one seems to know what .decode does for unicode. | What is the difference between encode/decode? | 1 | 0 | 0 | 111,429 |
447,107 | 2009-01-15T15:13:00.000 | 1 | 0 | 1 | 0 | python,string,unicode,character-encoding,python-2.x | 48,072,847 | 6 | false | 0 | 0 | The simple answer is that they are the exact opposite of each other.
The computer uses the very basic unit of byte to store and process information; it is meaningless for human eyes.
For example,'\xe4\xb8\xad\xe6\x96\x87' is the representation of two Chinese characters, but the computer only knows (meaning print or store) it is Chinese Characters when they are given a dictionary to look for that Chinese word, in this case, it is a "utf-8" dictionary, and it would fail to correctly show the intended Chinese word if you look into a different or wrong dictionary (using a different decoding method).
In the above case, the process for a computer to look for Chinese word is decode().
And the process of computer writing the Chinese into computer memory is encode().
So the encoded information is the raw bytes, and the decoded information is the raw bytes and the name of the dictionary to reference (but not the dictionary itself). | 3 | 185 | 0 | I've never been sure that I understand the difference between str/unicode decode and encode.
I know that str().decode() is for when you have a string of bytes that you know has a certain character encoding, given that encoding name it will return a unicode string.
I know that unicode().encode() converts unicode chars into a string of bytes according to a given encoding name.
But I don't understand what str().encode() and unicode().decode() are for. Can anyone explain, and possibly also correct anything else I've gotten wrong above?
EDIT:
Several answers give info on what .encode does on a string, but no-one seems to know what .decode does for unicode. | What is the difference between encode/decode? | 0.033321 | 0 | 0 | 111,429 |
448,095 | 2009-01-15T19:23:00.000 | 0 | 0 | 1 | 0 | java,python | 2,746,114 | 7 | false | 1 | 0 | I've used Java2Python. It's not too bad, you still need to understand the code as it doesn't do everything correctly, but it does help. | 6 | 6 | 0 | I'm about to port a smallish library from Java to Python and wanted some advice (smallish ~ a few thousand lines of code). I've studied the Java code a little, and noticed some design patterns that are common in both languages. However, there were definitely some Java-only idioms (singletons, etc) present that are generally not-well-received in Python-world.
I know at least one tool (j2py) exists that will turn a .java file into a .py file by walking the AST. Some initial experimentation yielded less than favorable results.
Should I even be considering using an automated tool to generate some code, or are the languages different enough that any tool would create enough re-work to have justified writing from scratch?
If tools aren't the devil, are there any besides j2py that can at least handle same-project import management? I don't expect any tool to match 3rd party libraries from one language to a substitute in another. | Porting library from Java to Python | 0 | 0 | 0 | 1,699 |
448,095 | 2009-01-15T19:23:00.000 | 9 | 0 | 1 | 0 | java,python | 448,137 | 7 | true | 1 | 0 | If it were me, I'd consider doing the work by hand. A couple thousand lines of code isn't a lot of code, and by rewriting it yourself (rather than translating it automatically), you'll be in a position to decide how to take advantage of Python idioms appropriately. (FWIW, I worked Java almost exclusively for 9 years, and I'm now working in Python, so I know the kind of translation you'd have to do.) | 6 | 6 | 0 | I'm about to port a smallish library from Java to Python and wanted some advice (smallish ~ a few thousand lines of code). I've studied the Java code a little, and noticed some design patterns that are common in both languages. However, there were definitely some Java-only idioms (singletons, etc) present that are generally not-well-received in Python-world.
I know at least one tool (j2py) exists that will turn a .java file into a .py file by walking the AST. Some initial experimentation yielded less than favorable results.
Should I even be considering using an automated tool to generate some code, or are the languages different enough that any tool would create enough re-work to have justified writing from scratch?
If tools aren't the devil, are there any besides j2py that can at least handle same-project import management? I don't expect any tool to match 3rd party libraries from one language to a substitute in another. | Porting library from Java to Python | 1.2 | 0 | 0 | 1,699 |
448,095 | 2009-01-15T19:23:00.000 | 2 | 0 | 1 | 0 | java,python | 448,330 | 7 | false | 1 | 0 | Jython's not what you're looking for in the final solution, but it will make the porting go much smoother.
My approach would be:
If there are existing tests (unit or otherwise), rewrite them in Jython (using Python's unittest)
Write some characterization tests in Jython (tests that record the current behavior)
Start porting class by class:
For each class, subclass it in Jython and port the methods one by one, making the method in the superclass abstract
After each change, run the tests!
You'll now have working Jython code that hopefully has minimal dependencies on Java.
Run the tests in CPython and fix whatever's left.
Refactor - you'll want to Pythonify the code, probably simplifying it a lot with Python idioms. This is safe and easy because of the tests.
I've this in the past with great success. | 6 | 6 | 0 | I'm about to port a smallish library from Java to Python and wanted some advice (smallish ~ a few thousand lines of code). I've studied the Java code a little, and noticed some design patterns that are common in both languages. However, there were definitely some Java-only idioms (singletons, etc) present that are generally not-well-received in Python-world.
I know at least one tool (j2py) exists that will turn a .java file into a .py file by walking the AST. Some initial experimentation yielded less than favorable results.
Should I even be considering using an automated tool to generate some code, or are the languages different enough that any tool would create enough re-work to have justified writing from scratch?
If tools aren't the devil, are there any besides j2py that can at least handle same-project import management? I don't expect any tool to match 3rd party libraries from one language to a substitute in another. | Porting library from Java to Python | 0.057081 | 0 | 0 | 1,699 |
448,095 | 2009-01-15T19:23:00.000 | 3 | 0 | 1 | 0 | java,python | 448,245 | 7 | false | 1 | 0 | I would write it again by hand. I don't know of any automated tools that would generate non-disgusting looking Python, and having ported Java code to Python myself, I found the result was both higher quality than the original and considerably shorter.
You gain quality because Python is more expressive (for example, anonymous inner class MouseAdapters and the like go away in favor of simple first class functions), and you also gain the benefit of writing it a second time.
It also is considerably shorter: for example, 99% of getters/setters can just be left out in favor of directly accessing the fields. For the other 1% which actually do something you can use property().
However as David mentioned, if you don't ever need to read or maintain the code, an automatic translator would be fine. | 6 | 6 | 0 | I'm about to port a smallish library from Java to Python and wanted some advice (smallish ~ a few thousand lines of code). I've studied the Java code a little, and noticed some design patterns that are common in both languages. However, there were definitely some Java-only idioms (singletons, etc) present that are generally not-well-received in Python-world.
I know at least one tool (j2py) exists that will turn a .java file into a .py file by walking the AST. Some initial experimentation yielded less than favorable results.
Should I even be considering using an automated tool to generate some code, or are the languages different enough that any tool would create enough re-work to have justified writing from scratch?
If tools aren't the devil, are there any besides j2py that can at least handle same-project import management? I don't expect any tool to match 3rd party libraries from one language to a substitute in another. | Porting library from Java to Python | 0.085505 | 0 | 0 | 1,699 |
448,095 | 2009-01-15T19:23:00.000 | 3 | 0 | 1 | 0 | java,python | 448,213 | 7 | false | 1 | 0 | Automatic translators (f2c, j2py, whatever) normally emit code you wouldn't want to touch by hand. This is fine when all you need to do is use the output (for example, if you have a C compiler and no Fortran compiler, f2c allows you to compile Fortran programs), but terrible when you need to do anything to the code afterwards. If you intend to use this as anything other than a black box, translate it by hand. At that size, it won't be too hard. | 6 | 6 | 0 | I'm about to port a smallish library from Java to Python and wanted some advice (smallish ~ a few thousand lines of code). I've studied the Java code a little, and noticed some design patterns that are common in both languages. However, there were definitely some Java-only idioms (singletons, etc) present that are generally not-well-received in Python-world.
I know at least one tool (j2py) exists that will turn a .java file into a .py file by walking the AST. Some initial experimentation yielded less than favorable results.
Should I even be considering using an automated tool to generate some code, or are the languages different enough that any tool would create enough re-work to have justified writing from scratch?
If tools aren't the devil, are there any besides j2py that can at least handle same-project import management? I don't expect any tool to match 3rd party libraries from one language to a substitute in another. | Porting library from Java to Python | 0.085505 | 0 | 0 | 1,699 |
448,095 | 2009-01-15T19:23:00.000 | 6 | 0 | 1 | 0 | java,python | 448,188 | 7 | false | 1 | 0 | Code is always better the second time you write it anyway....
Plus a few thousand lines of Java can probably be translated into a few hundred of Python. | 6 | 6 | 0 | I'm about to port a smallish library from Java to Python and wanted some advice (smallish ~ a few thousand lines of code). I've studied the Java code a little, and noticed some design patterns that are common in both languages. However, there were definitely some Java-only idioms (singletons, etc) present that are generally not-well-received in Python-world.
I know at least one tool (j2py) exists that will turn a .java file into a .py file by walking the AST. Some initial experimentation yielded less than favorable results.
Should I even be considering using an automated tool to generate some code, or are the languages different enough that any tool would create enough re-work to have justified writing from scratch?
If tools aren't the devil, are there any besides j2py that can at least handle same-project import management? I don't expect any tool to match 3rd party libraries from one language to a substitute in another. | Porting library from Java to Python | 1 | 0 | 0 | 1,699 |
448,837 | 2009-01-15T22:58:00.000 | 0 | 0 | 0 | 0 | python,windows,web-services,cgi | 449,199 | 9 | false | 1 | 0 | When setting this up, please be careful to restrict access to the scripts that take some action on your web server. It is not sufficient to place them in a directory where you just don't publish the URL, because sooner or later somebody will find them.
At the very least, put these scripts in a location that is password protected. You don't want just anybody out there on the internet being able to run your scripts. | 2 | 25 | 0 | I'm a hobbyist (and fairly new) programmer who has written several useful (to me) scripts in python to handle various system automation tasks that involve copying, renaming, and downloading files amongst other sundry activities.
I'd like to create a web page served from one of my systems that would merely present a few buttons which would allow me to initiate these scripts remotely.
The problem is that I don't know where to start investigating how to do this. Let's say I have a script called:
file_arranger.py
What do I need to do to have a webpage execute that script? This isn't meant for public consumption, so anything lightweight would be great. For bonus points, what do I need to look into to provide the web user with the output from such scripts?
edit: The first answer made me realize I forgot to include that this is a Win2k3 system. | How do I create a webpage with buttons that invoke various Python scripts on the system serving the webpage? | 0 | 0 | 1 | 38,798 |
448,837 | 2009-01-15T22:58:00.000 | 1 | 0 | 0 | 0 | python,windows,web-services,cgi | 449,062 | 9 | false | 1 | 0 | A simple cgi script (or set of scripts) is all you need to get started. The other answers have covered how to do this so I won't repeat it; instead, I will stress that using plain text will get you a long way. Just output the header (print("Content-type: text/plain\n") plus print adds its own newline to give you the needed blank line) and then run your normal program.
This way, any normal output from your script gets sent to the browser and you don't have to worry about HTML, escaping, frameworks, anything. "Do the simplest thing that could possibly work."
This is especially appropriate for non-interactive private administrative tasks like you describe, and lets you use identical programs from a shell with a minimum of fuss. Your driver, the page with the buttons, can be a static HTML file with single-button forms. Or even a list of links.
To advance from there, look at the logging module (for example, sending INFO messages to the browser but not the command line, or easily categorizing messages by using different loggers, by configuring your handlers), and then start to consider template engines and frameworks.
Don't output your own HTML and skip to using one of the many existing libraries—it'll save a ton of headache even spending a bit of extra time to learn the library. Or at the very least encapsulate your output by effectively writing your own mini-engine. | 2 | 25 | 0 | I'm a hobbyist (and fairly new) programmer who has written several useful (to me) scripts in python to handle various system automation tasks that involve copying, renaming, and downloading files amongst other sundry activities.
I'd like to create a web page served from one of my systems that would merely present a few buttons which would allow me to initiate these scripts remotely.
The problem is that I don't know where to start investigating how to do this. Let's say I have a script called:
file_arranger.py
What do I need to do to have a webpage execute that script? This isn't meant for public consumption, so anything lightweight would be great. For bonus points, what do I need to look into to provide the web user with the output from such scripts?
edit: The first answer made me realize I forgot to include that this is a Win2k3 system. | How do I create a webpage with buttons that invoke various Python scripts on the system serving the webpage? | 0.022219 | 0 | 1 | 38,798 |
450,210 | 2009-01-16T12:01:00.000 | 4 | 0 | 0 | 1 | python,windows,winapi,windows-vista,permissions | 450,297 | 4 | true | 0 | 0 | I recently wrote a App to pass a set of test to obtain the ISV status from Microsoft and I also add that condition.
The way I understood it was that if the user is Least Priveledge then he won't have permission to write in the system folders. So I approached the problem the the way Ishmaeel described. I try to create the file and catch the exception then inform the user that he doesn't have permission to write files to that directory.
In my understanding an Least-Priviledged user will not have the necessary permissions to write to those folders, if he has then he is not a Least-Priveledge user.
Should I stop bothering just because Windows Vista itself won't allow the Least-Privileged user to save any files in %WINDIR%?
In my opinion? Yes. | 2 | 6 | 0 | I have a code that creates file(s) in user-specified directory. User can point to a directory in which he can't create files, but he can rename it.
I have created directory for test purposes, let's call it C:\foo.
I have following permissions to C:\foo:
Traversing directory/Execute file
Removing subfolders and files
Removing
Read permissions
Change permissions
Take ownership
I don't have any of the following permissions to C:\foo:
Full Control
File creation
Folder creation
I have tried following approaches, so far:
os.access('C:\foo', os.W_OK) == True
st = os.stat('C:\foo')
mode = st[stat.ST_MODE]
mode & stat.S_IWRITE == True
I believe that this is caused by the fact that I can rename folder, so it is changeable for me. But it's content - not.
Does anyone know how can I write code that will check for a given directory if current user has permissions to create file in that directory?
In brief - I want to check if current user has File creation and Folder creation permissions for given folder name.
EDIT: The need for such code arisen from the Test case no 3 from 'Certified for Windows Vista' program, which states:
The application must not allow the Least-Privileged user to save any files to Windows System directory in order to pass this test case.
Should this be understood as 'Application may try to save file in Windows System directory, but shouldn't crash on failure?' or rather 'Application has to perform security checks before trying to save file?'
Should I stop bothering just because Windows Vista itself won't allow the Least-Privileged user to save any files in %WINDIR%? | How to check if a file can be created inside given directory on MS XP/Vista? | 1.2 | 0 | 0 | 3,469 |
450,210 | 2009-01-16T12:01:00.000 | 4 | 0 | 0 | 1 | python,windows,winapi,windows-vista,permissions | 450,259 | 4 | false | 0 | 0 | I wouldn't waste time and LOCs on checking for permissions. Ultimate test of file creation in Windows is the creation itself. Other factors may come into play (such as existing files (or worse, folders) with the same name, disk space, background processes. These conditions can even change between the time you make the initial check and the time you actually try to create your file.
So, if I had a scenario like that, I would just design my method to not lose any data in case of failure, to go ahead and try to create my file, and offer the user an option to change the selected directory and try again if creation fails. | 2 | 6 | 0 | I have a code that creates file(s) in user-specified directory. User can point to a directory in which he can't create files, but he can rename it.
I have created directory for test purposes, let's call it C:\foo.
I have following permissions to C:\foo:
Traversing directory/Execute file
Removing subfolders and files
Removing
Read permissions
Change permissions
Take ownership
I don't have any of the following permissions to C:\foo:
Full Control
File creation
Folder creation
I have tried following approaches, so far:
os.access('C:\foo', os.W_OK) == True
st = os.stat('C:\foo')
mode = st[stat.ST_MODE]
mode & stat.S_IWRITE == True
I believe that this is caused by the fact that I can rename folder, so it is changeable for me. But it's content - not.
Does anyone know how can I write code that will check for a given directory if current user has permissions to create file in that directory?
In brief - I want to check if current user has File creation and Folder creation permissions for given folder name.
EDIT: The need for such code arisen from the Test case no 3 from 'Certified for Windows Vista' program, which states:
The application must not allow the Least-Privileged user to save any files to Windows System directory in order to pass this test case.
Should this be understood as 'Application may try to save file in Windows System directory, but shouldn't crash on failure?' or rather 'Application has to perform security checks before trying to save file?'
Should I stop bothering just because Windows Vista itself won't allow the Least-Privileged user to save any files in %WINDIR%? | How to check if a file can be created inside given directory on MS XP/Vista? | 0.197375 | 0 | 0 | 3,469 |
450,290 | 2009-01-16T12:33:00.000 | 0 | 0 | 1 | 0 | python | 450,545 | 3 | false | 1 | 0 | Remember that in addition to setting PYTHONPATH in your system environment, you'll also want to assign DJANGO_SETTINGS_MODULE. | 1 | 2 | 0 | I am installing active python, django. I really dont know how to set the python path in vista environment system. first of all will it work in vista. | Python Path | 0 | 0 | 0 | 1,226 |
450,306 | 2009-01-16T12:38:00.000 | 0 | 0 | 0 | 0 | python,wxpython,wx.textctrl | 450,324 | 4 | false | 0 | 0 | Remove() should do the trick.
TextCtrl without wx.TE_RICH flag can't have more than 64 KB on Windows. | 2 | 3 | 0 | I am using a wx.TextCtrl to output text from a network daemon.
As the output is quite verbose, the size of text in the TextCtrl can become huge (BTW is there any limitation on the size of the contents of a TextCtrl?)
I would like to delete the top N lines from the TextCtrl when TextCtrl.GetNumberOfLines() exceeds a predefined treshold.
What is the best way to accomplish this? | Deleting lines from wx.TextCtrl | 0 | 0 | 0 | 3,535 |
450,306 | 2009-01-16T12:38:00.000 | 0 | 0 | 0 | 0 | python,wxpython,wx.textctrl | 450,315 | 4 | false | 0 | 0 | How about the Remove method of wx.TextCtrl?
Whenever you're about to add new text, you can check if the current text appears too long and remove some from the start. | 2 | 3 | 0 | I am using a wx.TextCtrl to output text from a network daemon.
As the output is quite verbose, the size of text in the TextCtrl can become huge (BTW is there any limitation on the size of the contents of a TextCtrl?)
I would like to delete the top N lines from the TextCtrl when TextCtrl.GetNumberOfLines() exceeds a predefined treshold.
What is the best way to accomplish this? | Deleting lines from wx.TextCtrl | 0 | 0 | 0 | 3,535 |
451,952 | 2009-01-16T20:51:00.000 | 13 | 0 | 0 | 0 | python,plone,zope,zodb,blobstorage | 2,664,479 | 4 | false | 0 | 0 | It should be safe to do a repozo backup of the Data.fs followed by an rsync of the blobstorage directory, as long as the database doesn't get packed while those two operations are happening.
This is because, at least when using blobs with FileStorage, modifications to a blob always results in the creation of a new file named based on the object id and transaction id. So if new or updated blobs are written after the Data.fs is backed up, it shouldn't be a problem, as the files that are referenced by the Data.fs should still be around. Deletion of a blob doesn't result in the file being removed until the database is packed, so that should be okay too.
Performing a backup in a different order, or with packing during the backup, may result in a backup Data.fs that references blobs that are not included in the backup. | 3 | 8 | 0 | I am using plone.app.blob to store large ZODB objects in a blobstorage directory. This reduces size pressure on Data.fs but I have not been able to find any advice on backing up this data.
I am already backing up Data.fs by pointing a network backup tool at a directory of repozo backups. Should I simply point that tool at the blobstorage directory to backup my blobs?
What if the database is being repacked or blobs are being added and deleted while the copy is taking place? Are there files in the blobstorage directory that must be copied over in a certain order? | What is the correct way to backup ZODB blobs? | 1 | 1 | 0 | 2,618 |
451,952 | 2009-01-16T20:51:00.000 | 3 | 0 | 0 | 0 | python,plone,zope,zodb,blobstorage | 453,942 | 4 | true | 0 | 0 | Backing up "blobstorage" will do it. No need for a special order or anything else, it's very simple.
All operations in Plone are fully transactional, so hitting the backup in the middle of a transaction should work just fine. This is why you can do live backups of the ZODB. Without knowing what file system you're on, I'd guess that it should work as intended. | 3 | 8 | 0 | I am using plone.app.blob to store large ZODB objects in a blobstorage directory. This reduces size pressure on Data.fs but I have not been able to find any advice on backing up this data.
I am already backing up Data.fs by pointing a network backup tool at a directory of repozo backups. Should I simply point that tool at the blobstorage directory to backup my blobs?
What if the database is being repacked or blobs are being added and deleted while the copy is taking place? Are there files in the blobstorage directory that must be copied over in a certain order? | What is the correct way to backup ZODB blobs? | 1.2 | 1 | 0 | 2,618 |
451,952 | 2009-01-16T20:51:00.000 | 1 | 0 | 0 | 0 | python,plone,zope,zodb,blobstorage | 676,364 | 4 | false | 0 | 0 | Your backup strategy for the FileStorage is fine. However, making a backup of any database that stores data in multiple files never is easy as your copy has to happen with no writes to the various files. For the FileStorage a blind stupid copy is fine as it's just a single file. (Using repozo is even better.)
In this case (with BlobStorage combined with FileStorage) I have to point to the regular backup advice:
take the db offline while making a file-system copy
use snapshot tools like LVM to freeze the disk at a given point
do a transactional export (not feasable in practice) | 3 | 8 | 0 | I am using plone.app.blob to store large ZODB objects in a blobstorage directory. This reduces size pressure on Data.fs but I have not been able to find any advice on backing up this data.
I am already backing up Data.fs by pointing a network backup tool at a directory of repozo backups. Should I simply point that tool at the blobstorage directory to backup my blobs?
What if the database is being repacked or blobs are being added and deleted while the copy is taking place? Are there files in the blobstorage directory that must be copied over in a certain order? | What is the correct way to backup ZODB blobs? | 0.049958 | 1 | 0 | 2,618 |
452,305 | 2009-01-16T22:38:00.000 | 0 | 1 | 1 | 0 | python,programming-languages | 452,352 | 12 | false | 0 | 0 | Dynamic languages are in general good for web apps because the speed of development. Python in particular has two advantages over most of them:
"batteries included" means lots of available libraries
Django. For me this is the only reason why i use Python instead of Lua (which i like a lot more). | 5 | 10 | 0 | What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web? | What are the benefits of using Python for web programming? | 0 | 0 | 0 | 15,173 |
452,305 | 2009-01-16T22:38:00.000 | 1 | 1 | 1 | 0 | python,programming-languages | 452,356 | 12 | false | 0 | 0 | GNU Mailman is another project written in python that is widely successful. | 5 | 10 | 0 | What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web? | What are the benefits of using Python for web programming? | 0.016665 | 0 | 0 | 15,173 |
452,305 | 2009-01-16T22:38:00.000 | 0 | 1 | 1 | 0 | python,programming-languages | 452,384 | 12 | false | 0 | 0 | Besides the frameworks...
Python's pervasive support for Unicode should make i18n much smoother.
A sane namespace system makes debugging much nicer, because it's typically easier to find where things are defined.
Python's inability to function as a standalone templating language should discourage the mixture of HTML with model code
Great standard library | 5 | 10 | 0 | What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web? | What are the benefits of using Python for web programming? | 0 | 0 | 0 | 15,173 |
452,305 | 2009-01-16T22:38:00.000 | 0 | 1 | 1 | 0 | python,programming-languages | 452,392 | 12 | false | 0 | 0 | Other examples of Python sites are Reddit and YouTube. | 5 | 10 | 0 | What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web? | What are the benefits of using Python for web programming? | 0 | 0 | 0 | 15,173 |
452,305 | 2009-01-16T22:38:00.000 | 1 | 1 | 1 | 0 | python,programming-languages | 452,600 | 12 | false | 0 | 0 | As many have pointed out, Django is a great reason to use Python...so in order to figure out why Python is great for web development, the best bet is to look at why it is a good language to build a framework like Django.
IMHO Python combines the cleanest, or at least one of the cleanest, metaprogramming models of any language with a very pure object orientation. This not only makes it possible to write extremely general abstractions that are easy to use, but also allows the abstractions to combine relatively cleanly with others. This is harder to do in languages that take a code-generation based approach to metaprogramming (e.g. Ruby). | 5 | 10 | 0 | What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web? | What are the benefits of using Python for web programming? | 0.016665 | 0 | 0 | 15,173 |
453,158 | 2009-01-17T11:19:00.000 | 4 | 1 | 0 | 0 | python,xml,json,twitter,twisted | 453,160 | 3 | false | 0 | 0 | RSS and Atom are XML formats.
JSON is a string which can be evaluated as Javascript code. | 2 | 6 | 0 | I'm new to web services and as an introduction I'm playing around with the Twitter API using the Twisted framework in python. I've read up on the different formats they offer, but it's still not clear to me which one I should use in my fairly simple project.
Specifically the practical difference between using JSON or XML is something I'd like guidance on. All I'm doing is requesting the public timeline and caching it locally.
Thanks. | What is the practical difference between xml, json, rss and atom when interfacing with Twitter? | 0.26052 | 0 | 1 | 8,204 |
453,158 | 2009-01-17T11:19:00.000 | 1 | 1 | 0 | 0 | python,xml,json,twitter,twisted | 453,164 | 3 | false | 0 | 0 | I would say the amount of data being sent over the wire is one factor. XML data stream will be bigger than JSON for the same data. But you can use whatever you know more/have more experience.
I would recommend JSON, as it's more "pythonic" than XML. | 2 | 6 | 0 | I'm new to web services and as an introduction I'm playing around with the Twitter API using the Twisted framework in python. I've read up on the different formats they offer, but it's still not clear to me which one I should use in my fairly simple project.
Specifically the practical difference between using JSON or XML is something I'd like guidance on. All I'm doing is requesting the public timeline and caching it locally.
Thanks. | What is the practical difference between xml, json, rss and atom when interfacing with Twitter? | 0.066568 | 0 | 1 | 8,204 |
454,456 | 2009-01-18T01:27:00.000 | 0 | 0 | 1 | 0 | python,regex,performance,file | 454,471 | 9 | false | 0 | 0 | For single line patterns you can iterate over the lines of the file, but for multi-line patterns, You will have to read all (or part, but that'll be hard to keep track of) of the file into memory. | 1 | 38 | 0 | I want to be able to run a regular expression on an entire file, but I'd like to be able to not have to read the whole file into memory at once as I may be working with rather large files in the future. Is there a way to do this? Thanks!
Clarification: I cannot read line-by-line because it can span multiple lines. | How do I re.search or re.match on a whole file without reading it all into memory? | 0 | 0 | 0 | 31,453 |
454,725 | 2009-01-18T06:01:00.000 | 1 | 0 | 1 | 0 | python,line-endings | 49,930,731 | 4 | false | 0 | 0 | os.linesep is important as it depends (as the name implied:)) on os.
E.g. on Windows, it is not "\n" but rather "\r\n".
But if you don't care about multi-platform stuff you can just use '\n'. | 1 | 90 | 0 | Is there an easy way to get the type of line ending that the current operating system uses? | Python get proper line ending | 0.049958 | 0 | 0 | 64,455 |
454,854 | 2009-01-18T09:13:00.000 | 5 | 0 | 0 | 0 | python,django,python-2.x | 28,278,997 | 32 | false | 1 | 0 | Go to your project directory with cd.
source/bin/activate (activate your env. if not previously).
Run the command easy_install MySQL-python | 5 | 493 | 0 | I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. I am using it in Windows Vista. | No module named MySQLdb | 0.03124 | 1 | 0 | 804,257 |
454,854 | 2009-01-18T09:13:00.000 | 6 | 0 | 0 | 0 | python,django,python-2.x | 58,246,337 | 32 | false | 1 | 0 | I personally recommend using pymysql instead of using the genuine MySQL connector, which provides you with a platform independent interface and could be installed through pip.
And you could edit the SQLAlchemy URL schema like this:
mysql+pymysql://username:passwd@host/database | 5 | 493 | 0 | I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. I am using it in Windows Vista. | No module named MySQLdb | 1 | 1 | 0 | 804,257 |
454,854 | 2009-01-18T09:13:00.000 | 93 | 0 | 0 | 0 | python,django,python-2.x | 38,310,817 | 32 | false | 1 | 0 | if your python version is 3.5, do a pip install mysqlclient, other things didn't work for me | 5 | 493 | 0 | I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. I am using it in Windows Vista. | No module named MySQLdb | 1 | 1 | 0 | 804,257 |
454,854 | 2009-01-18T09:13:00.000 | 2 | 0 | 0 | 0 | python,django,python-2.x | 58,825,148 | 32 | false | 1 | 0 | None of the above worked for me on an Ubuntu 18.04 fresh install via docker image.
The following solved it for me:
apt-get install holland python3-mysqldb | 5 | 493 | 0 | I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. I am using it in Windows Vista. | No module named MySQLdb | 0.012499 | 1 | 0 | 804,257 |
454,854 | 2009-01-18T09:13:00.000 | 0 | 0 | 0 | 0 | python,django,python-2.x | 72,496,371 | 32 | false | 1 | 0 | For CentOS 8 and Python3
$ sudo dnf install python3-mysqlclient -y | 5 | 493 | 0 | I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. I am using it in Windows Vista. | No module named MySQLdb | 0 | 1 | 0 | 804,257 |
454,944 | 2009-01-18T10:42:00.000 | 6 | 0 | 0 | 0 | python,django,message-queue | 714,637 | 8 | false | 1 | 0 | Stompserver is a good option. It's lightweight, easy to install and easy to use from Django/python.
We have a system using stompserver in production for sending out emails and processing other jobs asynchronously.
Django saves the emails to the database, a model.post_save handler in Django sends an event to stompserver and stompserver passes the event to a consumer process which does the asynchronous task (sends the email).
It scales up quite nicely because you can add consumer processes at runtime - two consumers can send twice as many emails, and the consumers can be on seperate machines. One slight complication is that each consumer needs its own named queue so Django needs to know how many consumers are available and send events to each queue in a round-robin way. (Two consumers listening on the same queue will both get each message = duplication). If you only want one consumer process then this isn't an issue.
We previously had processes which polled the database continuously for jobs but found that it was adding a lot of load to the system, even when nothing needed to be processed. | 4 | 44 | 0 | I have an application in Django, that needs to send a large number of emails to users in various use cases. I don't want to handle this synchronously within the application for obvious reasons.
Has anyone any recommendations for a message queuing server which integrates well with Python, or they have used on a Django project? The rest of my stack is Apache, mod_python, MySQL. | Advice on Python/Django and message queues | 1 | 0 | 0 | 20,229 |
454,944 | 2009-01-18T10:42:00.000 | 1 | 0 | 0 | 0 | python,django,message-queue | 3,696,792 | 8 | false | 1 | 0 | Is there anything wrong is solving this using the mail infrastructure? Like, every app server running their own mail daemons which will queue any locally submitted mail, which forward to a centralized mail server which can do the mail heavy lifting? | 4 | 44 | 0 | I have an application in Django, that needs to send a large number of emails to users in various use cases. I don't want to handle this synchronously within the application for obvious reasons.
Has anyone any recommendations for a message queuing server which integrates well with Python, or they have used on a Django project? The rest of my stack is Apache, mod_python, MySQL. | Advice on Python/Django and message queues | 0.024995 | 0 | 0 | 20,229 |
454,944 | 2009-01-18T10:42:00.000 | 0 | 0 | 0 | 0 | python,django,message-queue | 454,996 | 8 | false | 1 | 0 | If you already have MySQL installed, you could create a table to use as a "todo list" of sorts.
Threads synchronously add jobs to the table, and a batched task removes jobs as they're completed.
That way, there's no need to install and learn more software, and it should work fine as a persistent job store so long as you're not sending lots of email (like >10/sec). | 4 | 44 | 0 | I have an application in Django, that needs to send a large number of emails to users in various use cases. I don't want to handle this synchronously within the application for obvious reasons.
Has anyone any recommendations for a message queuing server which integrates well with Python, or they have used on a Django project? The rest of my stack is Apache, mod_python, MySQL. | Advice on Python/Django and message queues | 0 | 0 | 0 | 20,229 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.