New answers tagged python
0
Erlang has fault tolerance pattern inside the framework, and every process has a ready to use 'postal box' for caching messages, a very nice integration with other languages. It's a completely new paradigm compared to OO languages. To build the front-end you can use www.chicagoboss.org, and RabbitMQ to get the messages. Anyway, I saw that ElasticSearch is ...
0
The interpreters themselves are compiled and dependent on the platform they run on due to different OS and architecture concerns (for example different C libraries and file handling). So there is no way to get around the platform dependency entirely in the installation. However as you say there are ways to package it into a package so that it will be easier ...
2
MichaelT's comment is spot-on. Things like py2exe do the following:
bundle python runtime for a particular platform with your python code and all its dependencies
create a self-extracting executable that unpacks all of the above things and kicks off your script
You get a ready-to-run package for a single platform. You sacrifice portability.
1
I second statements that you should not be using NTP or going near the system clock for this. If you actually examine this requirement, you're going to find that you have the following needs:
How much time has elapsed since the previous frame so that you can advance any time-based stuff. This may be different on client and server if both tick at ...
1
How do you know which player's clock is correct? You don't, so use a reference clock.
NTP is overkill here - you only need ~1 second accuracy - so use rdate or pick something from one of many clock synchronisation algorithms.
One you've chosen a method, get each player's machine to pick up the time per that method (without changing their system clock). ...
-3
It don't see why not. Just be respectful and frame things in terms of how you would have done something differently or as a question of whether it might better if... etc. Even when experience levels are matched, code review can be as much an opportunity to learn from the reviewed as it is to learn from the reviewer. It's not usually about sitting in judgment ...
2
Do you believe that I could still do useful work for the project?
Yes, but be honest about your level of experience.
Some things you might be able to work on are the work items (bugs, tasks, etc.) that the team classified as "fairly trivial, no rush". This classification is from the viewpoint of someone who is comfortable with the existing codebase, so ...
2
Can I perform a code review although I am very inexperienced?
Yes, you could, and should join a code review whenever it is done (and you have free time). Even if you do not contribute, you can learn something new, therefore it is almost always useful.
Do you believe that I could still do useful work for the project?
Since you are new and ...
1
Most of the times no. But you have to answer (at least)the following questions first, just in case you are the exception:
Can you recognize possible security flaws by reading the source code? If yes, can you propose a solution?
Are you aware of a handful of coding best practices and able to catch them up? From freeing memory and not causing memory leaks, ...
7
I think it is definitely not OK to synchornize the clock in the system. User does not expect you to touch the system settings and many systems won't even let you to.
All you need is to have a correlation to convert timestamp from one side's clock to the other side's clock. On the other hand you need this correlation to be rather precise, say at least to a ...
0
Let me give some guiding principles.
Principle #1. As outlined in http://docs.python.org/2/reference/simple_stmts.html the performance overhead of asserts can be removed with a command line option, while still being there for debugging. If performance is a problem, do that. Leave the asserts. (But don't do anything important in the asserts!)
Principle ...
6
I think the part you missed is what "is" keyword actually does.
"is" tests references, or "identity" of an object. {} is an empty dictionary, expression "{} is {}" creates two empty dictionary. Their values are "equal" but their identities are not because those two dictionaries reside in different locations in memory as dictionary is an object which is ...
-1
Go for PHP it's easy to learn especially if you know Java like me. It has Java like syntax. (Making it that much easier to learn). php.net is a great place to learn stuff with W3Schools showing you the basics. But the logic and concepts are like Java. Have fun, I did moved form java to php/perl. And start building your site and learn in the process. it's ...
7
Given a few days to learn the syntax, a good programmer should be able to code in any language.
Putting aside my personal preference for Python, there are a few key factors that will influence your friends first language.
If you are the teacher, teach a language you know - If your friend knows no programming, they need some one who knows what they are ...
1
IMO Python is a perfect learning language (though the first versions were smaller so better...). One can learn the basics pretty fast, and it's even good to use for many purposes in development.
As it has strong support for functional style it's indeed good for demonstration of concepts too.
JS can be learnt as on top of it without problems. I second your ...
1
I came from Pascal, C background and then went for JavaScript and only then to Python.
Whitespace is like a religion and I hated it in Python for around 2 days. After that I felt it's good as it is so it's not a major point.
I would recommend Python as JavaScript has it's quirks and can make a beginner a little confused:
Incompatible browsers
DOM
...
1
While not a general solution, and certainly not ideal, one way to tackle this particular problem is to use the server side template processing language to do block comments for nested code comment elements. This leaves the content essentially intact, but prevents sending it to the client browser.
That doesn't help a lot if the file is otherwise straight ...
10
C and C++ does have a nested block comments:
#if 0
#endif
Many highlighting editors understand this as a comment and many other will at least highlight it as any other conditionally disabled code.
In many other languages you have to rely on editor support. For languages that only have line-based comments (perl, python, ruby, shell...) it is rather simple ...
32
The best solution is, obviously, to just not nest your comments. Nested comments are usually a sign that you are using comments wrong. The most common example is commented-out code that contains comments itself, and the fix is to remove the code instead of commenting it out.
That said, many programming languages have more than one type of comment syntax, ...
0
You can run external commands with the subprocess module; since you pass arguments to a command as a list to the subprocess module functions, it is trivial to create those arguments with a python script.
2
You have pretty much the same options, actually. WebKit is cross-platform, as are other browser engines.
Also, I'd think that quite a lot of general purpose mainstream programming languages would already provide a "WebView" component that should be good enough for most use cases.
For instance, Java has had this capability for quite a long while. Though I'd ...
2
Unless the performance overhead of using the web service is an issue, you should definitely use your public API.
This will help you get a consistent behavior between your application and the consumers. It will also avoid code duplication and the best part - if you break your web service you will most likely be the first one to notice it.
The concept is ...
0
Without understanding how your web-service is set up and how web methods are intended to be called, I don't think there is a way to say you should implement it in a specific way.
For best practice and practicality, I would implement it as close to the way you intend developers to consume/implement it as possible.
2
It really depends on the library you're using. Some of them could be closing the connection on their own (Note: I checked the builtin sqlite3 library, and it does not). Python will call a destructor when an object goes out of scope, and these libraries might implement a destructor that closes the connections gracefully.
However, that might not be the case! ...
2
This is one of those areas where it is impossible to give definitive answers, because it concerns a trade-off.
As you found out, neither OO, nor vector-based is always superior, but it all depends on how the software will be used.
You could try to combine the best of both and create both a Volatility object and a VolatilitySeries object, where the second ...
1
On what principles would you decide to add or exclude them from a language?
I don't think that's the right question. Every language designer has something in mind when they design their language, and that often will dictate some of the answers. For example, if you are designing for type-safety, then you won't allow numbers to be true or false. If you ...
2
The problem with "falsy" values is that they inevitably lead to ambiguities between in- and out-of-bounds responses: cases where an operation returns a "falsy" value that could mean either failure to produce an answer or success at producing an answer whose value is the "falsy" value.
One familiar example would be Java's Map<K,V>.get(K key) method, ...
0
There are web application frameworks that abstract away HTML and JavaScript, but honestly the cure is often worse than the disease. (eg, Google Web Toolkit).
Do yourself a favour though, and learn jQuery, CoffeeScript and/or other javascript frameworks to spare some of the most tedious details. Similarly, consider using something like Haml or HamlPy to work ...
0
Knowing Javascript is a plus as it helps you creating web apps. I think HTML is the best to have a good solid knowledge on and HTML5 is nice because it integrates well with CSS3 and JavaScript. I would recommend browsing through the courses at Microsoft Virtual Academy.
They have over 200 different course options and they’re all free and expert led. I ...
6
I've only skimmed the requirements, but I'd be thinking something simple like this:
Give each task a letter.
Generate a task sequence string (eg, EBDFA) for a user.
Look at the first letter to decide what task to do next.
Carry out that task.
Strip the first letter off, pass the rest in the URL.
Go to step 3.
Keep it simple. Don't create models you ...
0
I came across a situation like this in an Application I helped create.
I called it the User Sanity Test, because I was testing the User model and the possible states it could be in with regards to its relations to other models.
Things I would test were, Had they set an email address, Did they have valid billing details, have they created their first ...
1
To see that it can't be just a question of shifting points around, just draw a frame around your image: In the rotated version, the image will have diagonal edges and so won't even fit in the dimensions of the original image.
So, to rotate it you'll have to compute where each pixel goes. Note that the top left point (0,1) will not end up at (1,1) but at a ...
2
I'm reminded of the classic joke with the punchline "I wouldn't start from here.".
Since there is different behaviour associated with each specific browser, it seems to me that you actually have a number of different subclasses of the Browser base class:
The key difference between the subclasses being the differences in behaviour, not the difference in ...
2
Put the hard-coded strings into a configuration file, fx using the INI format. That way you can exchange them without touching code.
paths.ini
Chrome="~/Library/Application Support/Google/Default/Bookmarks"
Safari="~/Library/Safari/Bookmarks.plist"
or
chrome.ini
path="~/Library/Application Support/Google/Default/Bookmarks"
safari.ini
...
0
I would start with an enum with values like safari, chrome, opera ... and a constructor that takes a default path and maybe add methods to handle edge cases.
0
For getting notified when exploits exist there are RSS feeds, services and products out there that will let you know about exploits. At the very least any admin should probably be following CVE or NVD (which includes CVE).
How to manage exploits in libraries used by your application, but not in the virtualenv? For example ImageMagick, the python ...
1
We use buildout to create deployments that are reproduceable and isolated.
A buildout acts like a virtualenv in that it lets you install eggs, keeping them separate from your Python installation, and it acts like pip in that you can control what versions are used. But buildout is also a build tool, with recipes you can make it build arbitrary parts as ...
0
Metaclasses are a powerful tool. Most of the time they are not needed, but it looks like you have solid reasons for doing so. I do not see your use of metaclasses, or lack thereof, affecting your package's adoption on PyPI.
2
In Python it's more of a something vs nothing concept, and it's incredibly convenient, plus much more readable, to have one's custom classes set to show as nothing (False) if they don't have a meaningful value when used in boolean tests.
Nearly all my own classes support it (lot's of container-type classes).
3
Python code
As soon as your application is a well-behaved egg, or a set of eggs, and you can easily deploy it into a virtualenv using pip or easy_install, you should be fine on any platform.
Things to pay attention to:
Native-code dependencies. You might depend on some eggs that include these (like psycopg); make sure that such an egg is equally ...
7
Don't know about python, but I've moved Java applications from Windows to Linux and vice-versa. Java makes the "write once, run anywhere" claim which may not be 100% true, but with very little work I was able to make it true enough (basically everything works great on Linux, a few issues on Windows).
I'll use W and L for Windows and Linux:
W: files and ...
2
If you always want to rotate an image by a specific angle each time, you only need to do the heavy math once (and really, it's not that heavy). The best way to do this is by working the process backwards. For every pixel in the destination image, you calculate the corresponding location in the starting image. This "source" pixel coordinate is saved in what ...
2
there's no way to do rotation by arbitrary angles without sines and cosines, but it is possible to optimize the calculation depending on what other constraints you're prepared to impose. This can get very complicated, but can result in huge improvements for the "special case" you've defined.
If your images are all the same size and reasonably small, like ...
2
Haskell too has the concept of falsy and I use them all the time.
Assume I have a handful of values and I need to fail if any one of those values are "false" (bools would be false, lists would be empty...). I can use the Maybe monoid to easily check if any of them are considered false based on their type.
True, the "if" statement in Haskell still only ...
1
I use them to my advantage in Javascript all the time. In Javascript, the falsy values are undefined, null, false, NaN, 0 and ""
It is just much easier to read:
if( !str ) {
}
instead of
if( str == null || str.length() == 0 ) {
}
or str == null || str.equals("") or bunch of other just as bad equivalents that you need to use in Java.
I do recall an ...
1
Downloading the contents of a website can cause a wide range of problems for the website owners.
Bottleneck the server by using all available resources to feed your script requests.
Make a mistake and perform requests that would appear like an attack.
Get stuck in what is called a robot trap and keep downloading the same page because the URL constantly ...
0
Scraping is more like stealing. It is using a content without permission. Otherwise it would be an API which provides you the data that you seek.
So if you know how to open some one's door lock, you can open it. But if he changes his door lock with another brand then you have to figure out how to handle that.
2
Yes. Python has a library which will give you an option to implement telnet application. Look at this link. And here is a video that might help you.
And there are many other languages that support telnet, for an instance java. So googling will definitely give you a lot of options. I recommend you to go with one language in which you fell you are good and ...
1
You'll have to group your users according to the flow assignments. For each usergroup you have sequence of pages. The data model will then be something like
User --> UserGroup <-- Sequences
+id +id +user_group_id
+name +current_step
+user_group_id +next_step
On each single page ...
Top 50 recent answers are included


