Re: Why did Quora choose Python for its development?

2011-05-23 Thread Aleksandar Radulovic
Hi,

I'm going to skip the Perl vs. Python flame-bait and correct your one statement.

On Sun, May 22, 2011 at 7:44 AM, Octavian Rasnita  wrote:
> Somebody told that C# and Objective C are good languages. They might be good, 
> but they are proprietary, and not only that they are proprietary, but they 
> need to be ran under platforms that cannot be used freely, so from the 
> freedom point of view, Perl, Ruby, Python and Java are the ways to go.

Neither of those are proprietary and can, in fact, be used freely. GNU
compiler compiles objective-c code with no problem and then there's
Mono for C# and .NET development on multiple platforms.

But if by proprietary you mean the libraries and APIs that complement
those languages, the it's worth noting that Mono implements most of
.NET framework and it is free. If you want "free" Cocoa APIs (or other
Obj-C frameworks) look into GnuSTEP.

Best regards,
alex.



-- 
a lex 13 x
http://www.a13x.info
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sloooooowwwww WSGI restart

2009-01-28 Thread Aleksandar Radulovic
Hi there,

On Wed, Jan 28, 2009 at 9:35 PM, Ron Garret  wrote:
> I'm running a WSGI app under apache/mod_wsgi and I've noticed that

Off the bat, there's no reason to run an app under apache/mod_wsgi
while developing it,
ie. if u use Pylons or TurboGears, there's an easier way to serve the
app (using paster
or cherrypy).

Secondly, why are you restarting apache after code changes? In normal
circumstances,
you shouldn't have to do that.

-- 
a lex 13 x
http://www.a13x.info
--
http://mail.python.org/mailman/listinfo/python-list


Re: New to python, open source Mac OS X IDE?

2009-01-28 Thread Aleksandar Radulovic
On Tue, Jan 27, 2009 at 11:06 PM, joseph.a.mar...@gmail.com
 wrote:
> I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you
> even use an IDE for Python?

I'm on a Mac, too. I don't use a full-fledged IDE for Python
development, nor I think it's
necessary.

> Any recommendations on open source Python environments?

Komodo Edit looks very professional and very usable. Other
alternatives are PyDev w/ Eclipse,
but I opted for TextMate - it has excellent features. I highly
recommend spending ~$50 on it,
it's money well spent.


-- 
a lex 13 x
http://www.a13x.info
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sloooooowwwww WSGI restart

2009-01-29 Thread Aleksandar Radulovic
Graham,

On Thu, Jan 29, 2009 at 1:16 AM, Graham Dumpleton
 wrote:
> Sorry, you are wrong to assume that an Apache restart is not be
> required.
> If you are using mod_wsgi embedded mode, or mod_python, then a code
> change will always require a full restart of Apache.

I am running several middleware apps I'm working on under mod_python
(simple setup using mod_python.publisher handler) and so far, haven't
had the reason to restart apache at all.

> Thus, the conjecture that Apache/mod_wsgi cannot be used and that
> CherryPy WSGI server or Paster server must be used when developing a
> Python web application is false. If using mod_wsgi then daemon mode

Not sure what (or whom) you're referring to. IMO, developing TG/Pylons/Django
apps is much convinient with embedded web server (cherrypy or paster) as
it is possible to do rapid development without resorting to restarts.

Example with Pylons:
$ paster serve development.ini --reload

This will start a subprocess which monitors file changes.

Regards,
alex.
-- 
a lex 13 x
http://www.a13x.info
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sloooooowwwww WSGI restart

2009-01-29 Thread Aleksandar Radulovic
Graham,

On Thu, Jan 29, 2009 at 1:00 PM, Graham Dumpleton
 wrote:

> In other words, it is not universal that any code change will be
> automatically detected and a reload occur. There are also various
> caveats on what mod_python module importer does, as it is reloading
> modules into an existing process and not restarting the whole.
> If you are not careful, weird things can happen.

Considering I'm not changing any of the modules (ie. working only on the
source tree in the project itself which is published by mod_python.publisher)
I haven't seen the need to restart Apache.

There are caveats, of course - but in day-to-day work, I haven't noticed
any difficulties and need to fully restart Apache.

> It was a general statement. There are various people on different
> forums and irc channels who keep saying that a full Apache restart is
> required with Apache/mod_wsgi when making code changes. Am just
> stating for the record that that isn't true.

We agree here. Someone posted a link earlier explaining the settings of
mod_wsgi (maybe it was you) where it's easy to configure it to detect
code changes and reload the code. Hence my questions from the begining
of the thread.

There are custom built code-reloading modules (and techniques) which can
also be used.

> So, depends on how closely you want your development environment to
> mirror production so that issues are picked up sooner, rather than
> only at the point of deployment to a production system when you are
> under pressure.

Ideally, you would want the environments to be as closely related (in terms
of setup) as possible. In my development, i try to keep the integration
environment a mirror of production, but (as mentioned) keep the local (dev)
environment as suitable to my needs as possible.

Continuous integration system would help in deploying the code to integration
for integration testing and final checks before hitting production (which is a
manual process).

Rushing things into production is never a good think(tm). All it needs is a bit
of careful planning, but I'm going way too off-topic here.

Regards,
alex.
-- 
a lex 13 x
http://www.a13x.info
--
http://mail.python.org/mailman/listinfo/python-list


Re: Java to Python

2009-02-07 Thread Aleksandar Radulovic
Hi,

This looks like a perfect job for httplib and urllib2 modules.

On Sat, Feb 7, 2009 at 4:49 PM, zaheer agadi  wrote:
> Hi Thanks for replying ..
> I am actually looking for the pure Python options
>
> Are there any equivalent clasees  for the following
>
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.HttpException;
> import
> org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.apache.commons.httpclient.protocol.Protocol;
>
>
> Thanks for your help
> -Zaheer
>
> On Sat, Feb 7, 2009 at 9:57 PM, Banibrata Dutta 
> wrote:
>>
>> Jython is not an option ?
>>
>> On Sat, Feb 7, 2009 at 9:54 PM,  wrote:
>>>
>>> Hi
>>>
>>> I have a following class that is written Java and makes use of apache
>>> http client library,I am new to python can any one suggest me a python
>>> equivalent of this following class,
>>>
>>> Thanks ,
>>>
>>> public class Authenticate{
>>>
>>>  private String storageUserName=null;
>>>private String storagePassword=null;
>>>private String authorization=null;
>>>private String identityHostName = null;
>>>private String identityPortNumber = null;
>>>
>>>private String accessKey=null;
>>>private String secretKey=null;
>>>
>>>public String getStoragePassword() {
>>>return storagePassword;
>>>}
>>>
>>>public void setStoragePassword(String storagePassword) {
>>>this.storagePassword = storagePassword;
>>>}
>>>
>>>public String getStorageUserName() {
>>>return storageUserName;
>>>}
>>>
>>>public void setStorageUserName(String storageUserName) {
>>>this.storageUserName = storageUserName;
>>>}
>>>
>>>public String getIdentityHostName() {
>>>return identityHostName;
>>>}
>>>
>>>public void setIdentityHostName(String identityHostName) {
>>>this.identityHostName = identityHostName;
>>>}
>>>
>>>public String getIdentityPortNumber() {
>>>return identityPortNumber;
>>>}
>>>
>>>public void setIdentityPortNumber(String identityPortNumber) {
>>>this.identityPortNumber = identityPortNumber;
>>>}
>>>
>>>public String getAccessKey() {
>>>return accessKey;
>>>}
>>>
>>>public void setAccessKey(String accessKey) {
>>>this.accessKey = accessKey;
>>>}
>>>
>>>public String getSecretKey() {
>>>return secretKey;
>>>}
>>>
>>>public void setSecretKey(String secretKey) {
>>>this.secretKey = secretKey;
>>>}
>>>
>>>
>>> /**
>>> * Convenience string for Base 64 encoding.
>>> */
>>>private static final String BASE64_CHARS =
>>>"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
>>>"abcdefghijklmnopqrstuvwxyz" +
>>>"0123456789+/";
>>>
>>>/**
>>> * Encode the specified credentials into a String as required
>>> by
>>> * HTTP Basic Authentication (http://www.ietf.org/rfc/
>>> rfc2617.txt">RFC 2617).
>>> *
>>> * @param username Username to be encoded
>>> * @param password Password to be encoded
>>> * @return String string containing encoded username and password.
>>> */
>>>public String encodeCredentialsBasic(String username, String
>>> password) {
>>>String encode = username + ":" + password;
>>>int paddingCount = (3 - (encode.length() % 3)) % 3;
>>>encode += "\0\0".substring(0, paddingCount);
>>>StringBuilder encoded = new StringBuilder();
>>>
>>>for (int i = 0; i < encode.length(); i += 3) {
>>>}
>>>return encoded.toString();
>>>}
>>>
>>>public void fetchDetails(){
>>>HttpClient client=new HttpClient();
>>>//reqDetails = new RequestDetails();
>>>//String identityURL=MessageUtil.getMessage
>>> ("IDENTITY_INSTANCE");
>>>//int portNumber=Integer.parseInt(MessageUtil.getMessage
>>> ("IDENTITY_PORT"));
>>>authorization="Basic " + encodeCredentialsBasic
>>> (storageUserName, storagePassword);
>>>String url="https://"+identityHostName+
>>>":"+identityPortNumber+"/test/ndcsd2/persons/"+UserName
>>> +"/attributes/";
>>>
>>>Protocol https=null;
>>>//try {
>>>https = new Protocol("https", new
>>> EasySSLProtocolSocketFactory(), Integer.parseInt(identityPortNumber));
>>>/*} catch (GeneralSecurityException ex) {
>>>Logger.getLogger(Authenticate.class.getName()).log
>>> (Level.SEVERE, null, ex);
>>>} catch (IOException ex) {
>>>Logger.getLogger(Authenticate.class.getName()).log
>>> (Level.SEVERE, null, ex);
>>>}*/
>>>Protocol.registerProtocol("https", https);
>>>GetMethod method=new GetMethod(url);
>>>method.setRequestHeader("Authorization",authorization);
>>>method.setRequestHeader("Accept","application/xml");
>>>try {
>>>int responseCode=client.executeMethod(method);
>>>

Re: Java to Python

2009-02-07 Thread Aleksandar Radulovic
Hi,

On Sat, Feb 7, 2009 at 5:28 PM, zaheer agadi  wrote:
> Thanks Alex,
>
>  Can you provide me more details on httplib and urllib ?

The details can be found in Python documentation (http://python.org/doc),
on these pages:
http://docs.python.org/library/httplib.html

I'm sure you can figure out the location of the documentation for the urllib2
module. Documentation includes examples too.


Regards,
alex.
-- 
a lex 13 x
http://www.a13x.info
--
http://mail.python.org/mailman/listinfo/python-list


Re: mod_python resources

2008-12-16 Thread Aleksandar Radulovic
On Tue, Dec 16, 2008 at 8:22 PM, tmallen  wrote:
> Are there any good tutorials out there for setting up Apache with
> mod_python?

Apart from the (clear and concise) information in the mod_python documentation?
Starts here: http://www.modpython.org/live/current/doc-html/installation.html

Compiling is as easy as:
$ ./configure --with-apxs=/usr/local/apache/bin/apxs
$ make
$ sudo make install (if you have sudo)

Configuring Apache is as easy as adding the lines in the apache config file:

LoadModule python_module libexec/mod_python.so
Alias /py /somedirectory


AllowOverride None
Order allow,deny
Allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On


That's about it.. For testing, continue reading the mod_python manual.

-- 
a lex 13 x
http://www.a13x.info
--
http://mail.python.org/mailman/listinfo/python-list


Re: utf-8 read/write file

2008-10-08 Thread Aleksandar Radulovic
Hi,

What is the encoding of the file1 you're reading from? I just ran
tests on my machine (OS X)
with both python2.5 and 2.6 and was able to read from a file containing:
"život je lep"

The file is UTF-8 encoded.

>>> data = open("test.txt").read()
>>> data
'\xc5\xbeivot je lep.'
>>> f = open("test2.txt", "wb")
>>> f.write(data)
>>> f.close()

mac-alex:~ alex$ file test.txt
test.txt: UTF-8 Unicode text, with no line terminators
mac-alex:~ alex$ file test2.txt
test2.txt: UTF-8 Unicode text, with no line terminators
mac-alex:~ alex$

Files test.txt and test2.txt are identical.

Regards,
alex.


2008/10/8 gigs <[EMAIL PROTECTED]>:
> Benjamin wrote:
>>
>> On Oct 8, 12:49 pm, Bruno <[EMAIL PROTECTED]> wrote:
>>>
>>> Hi!
>>>
>>> I have big .txt file which i want to read, process and write to another
>>> .txt file.
>>> I have done script for that, but im having problem with croatian
>>> characters
>>> (Š,Đ,Ž,Č,Ć).
>>
>> Can you show us what you have so far?
>>
>>> How can I read/write from/to file in utf-8 encoding?
>>
>> import codecs
>> data = codecs.open("my-utf8-file.txt").read()
>>
>>> I read file with fileinput.input.
>>>
>>> thanks
>>
> I have tried with codecs, but when i use encoding="utf-8" i get this error
> on word : život
>
> Traceback (most recent call last):
>  File "C:\Users\Administrator\Desktop\getcontent.py", line 43, in 
>encoding="utf-8").readlines()
>  File "C:\Python25\Lib\codecs.py", line 626, in readlines
>return self.reader.readlines(sizehint)
>  File "C:\Python25\Lib\codecs.py", line 535, in readlines
>data = self.read()
>  File "C:\Python25\Lib\codecs.py", line 424, in read
>newchars, decodedbytes = self.decode(data, self.errors)
> UnicodeDecodeError: 'utf8' codec can't decode byte 0x9e in position 0:
> unexpected code byte
>
>
> i just need to read from file1.txt, process (its simple text processing)
> some words and write them to file2.txt without loss of croatian characters.
> (šđžčć)
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
a lex 13 x
--
http://mail.python.org/mailman/listinfo/python-list


Re: concurrency program design stackless python tasklet or python thread?

2008-11-11 Thread Aleksandar Radulovic
Hi there,

On Tue, Nov 11, 2008 at 5:57 AM, davy zhang <[EMAIL PROTECTED]> wrote:
> first here is my basic idea is every actor holds their own msg queue,
> the process function will handle the message as soon as the dispatcher
> object put the message in.

Using stackless, every tasklet can have a channel which it uses to communicate
with other tasklets. The tasklet is blocked until there's something on
the channel
to receive.

> This idea naturally leads me to place every actor in a separate thread
> waiting for msg

You can have actors with many separate tasklets waiting for messages, still
being relatively lightweight, meaning you can run thousands of tasklets without
serious lack of performance.

> but I found the tasklet is really a lined-up sequence , that means if
> a tasklet blocked or do some time consuming calculation, the other
> tasklets can not get the cpu slice

This is cooperative scheduling, which you can choose not to use with Stackless
(instead, use preemptive scheduling). If you determine that one particular
task is taking too much cpu, you can declaratively call stackless.schedule()
and put that task back to the scheduler queue and allow other tasks to
have a go.

> so we must design very carefully to avoid the big job for single task

That's right - with cooperative scheduling careful design is the key.

> I am just confused why the stackless python is said to be good at
> concurrency program model or just I get a wrong idea to practice?

Stackless is an extremely lightweight way into concurrent programming.
I have personally used it in few projects and i quite like how lightweight
it is and how easy it is to write concurrent programs.

On the plus side, Stackless developers have plenty of examples and
common idioms of how Stackless should be used, which I highly recommend
you to check out. You might find a solution to your problem right there
amongst the examples.


Check it all out on http://www.stackless.com

-- 
a lex 13 x
http://www.a13x.info
--
http://mail.python.org/mailman/listinfo/python-list


Re: redirecting stdout/err to mysql table

2008-11-19 Thread Aleksandar Radulovic
On Tue, Nov 18, 2008 at 7:07 PM, n00b <[EMAIL PROTECTED]> wrote:
> greetings,
>
> i need to log to the db directly and wrote a little script to do so.
> since i'm pretty new to python,
> i was wondering if a) you could review the enclosed code and b)
> provide suggestions to harden to code to turn it into a more general,
> broadly reusable class.

First of all, your code is not quite pythonic and it will also open the
connection to the database *every* time you log. That can be quite
expensive and generally is not advisable. Plus it may block your code.

I suggest checking out (already existing) logging module in Python
distribution and extend the BaseHandler to implement the logging to
a database.

I highly recommend implementing pooling of connections to the DB
(ie. by simply using SqlAlchemy instead of direct MySQLDb module).



-- 
a lex 13 x
http://www.a13x.info
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can I write a binary windows executable with Python?

2008-08-29 Thread Aleksandar Radulovic
Hi,

What you're probably referring to is py2exe tool (http://www.py2exe.org/) which
creates windows executable programs out of python scripts. Once created,
such executable can be run on a Windows machine without Python installed.

Psyco, on the other hand, is a tool that greatly optimizes and
increases execution
speed of python scripts.

-alex.

On Fri, Aug 29, 2008 at 10:46 PM, walterbyrd <[EMAIL PROTECTED]> wrote:
> I have heard about Pysco. But does create a single executable that can
> run without Python being installed? Or does that just compile the
> libraries?
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
a lex 13 x
--
http://mail.python.org/mailman/listinfo/python-list