Re: [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-25 Thread prilisauer
Hey :-P I think I should rename the threads name into a new "Doc" project, 
I'm sure It won't take much time to fill a book with our knowledge. 

Thanks to Rick, you have Posted exactly what I wanted to ask. I know the that 
__variable = 'xyz'
_variable = 'xyz'

are used to make them private, but I haven't found it for methods. Thanks :)

I also don't think you're off topic! It's a big grey scale :-) and for me the 
first post till the last one is a part of my "question"

PEP, is nice, it tooks me a few days to get trough all your input and my code. 
Anyway is there also a best practice for naming? eg.: module_class_sub() or 
wording? eg.: socket: send() recv() -> recv is kept short. according PEP8??


It seems, my english slowly getting better again, If my colleagues would see 
what I'm writting here they won't belive me. I've worked at the Pharmaceutical 
IT and made Codereviews and programming for medical software. I still can't 
belive what I've forgotton the last two years. But still PEP etc. isn't far 
that hard written like pharm eu, usp, and 21CFR. Shame on me, but I will come 
back, after I've finished.

BR
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-25 Thread Steven D'Aprano
On Mon, 24 Dec 2012 00:19:18 -0500, Dave Angel wrote:

> Nobody's going to be able to understand your code if you persist in
> using self in unpythonic ways.  It's used as the first argument of a
> class method. Period.

To be pedantic, "self" is the conventional argument for *instance* 
methods, not class methods. For class methods, the conventional first 
argument is "cls", not "self".



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-25 Thread prilisauer
Hello Steven,

to "learn python" I've bought a book, and it's not a "thin" one :-) it's more a 
788p. long documentation about python.

BUT! I have to say: The autor started using the "self." argument at the 
chapter classes. So You've shown me the book descr. non "correct" way. Better 
using this book heating my home?! :-)

Patrick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-25 Thread Dave Angel
On 12/25/2012 09:41 AM, prilisa...@googlemail.com wrote:
> Hello Steven,
>
> to "learn python" I've bought a book, and it's not a "thin" one :-) it's more 
> a 788p. long documentation about python.
>
> BUT! I have to say: The autor started using the "self." argument at the 
> chapter classes. So You've shown me the book descr. non "correct" way. Better 
> using this book heating my home?! :-)
>
> Patrick

You still are being imprecise.  You don't give a title or author, and
you refer to the "chapter classes" whatever that is.  Do you mean the
chapter about classes?  If so, that's exactly where 'self' should be
introduced.

How about copying an example function that uses self, that you think is
incorrect ?  If it is incorrect, perhaps we should give the author some
feedback.

We all make mistakes, like my referring to class methods when I meant
instance methods.  But I didn't figure it was time to introduce class
methods, so I wasn't trying to make the distinction.  My error.

-- 

DaveA

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-25 Thread prilisauer
By the way i haven't add the Title because it's a german only book named
"Python 3: Das umfangreiche Handbuch, Published by Galileo Computing" 

and also, because I've registered to first check if the Autor has allready 
published a update. Too many information's could ocurre in an avalanche 

I see a big failure:

1. I answer to quick

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Scrapy/XPath help

2012-12-25 Thread donarb
On Friday, December 21, 2012 1:58:47 PM UTC-8, Always Learning wrote:
> The errors I get are
> >>File 
> >>"C:\python27\lib\site-packages\scrapy-0.16.3-py2.7.egg\scrapy\selector\lxmlsel.py",
> >> line 47, in select
> 
> >>raise ValueError("Invalid XPath: %s" % xpath)
> 
> >>exceptions.ValueError: Invalid XPath: /span[@class='team-name'/text()
> 


You're missing a right bracket in the xpath expression:

/span[@class='team-name']/text()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-25 Thread Rick Johnson
On Tuesday, December 25, 2012 11:10:49 AM UTC-6, Dave Angel wrote:

> We all make mistakes, like my referring to class methods when I
> meant instance methods. 

This mistake reminded of how people in this group (maybe not you in particular) 
happily accept the terms "instance method" and "class method" HOWEVER if you 
_dare_ use the terms "instance variable" or "class variable" you get a swift 
rebuke. 

Would anyone care for another serving of logically inconsistent py? 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-25 Thread Steven D'Aprano
On Tue, 25 Dec 2012 12:16:16 -0800, Rick Johnson wrote:

> On Tuesday, December 25, 2012 11:10:49 AM UTC-6, Dave Angel wrote:
> 
>> We all make mistakes, like my referring to class methods when I meant
>> instance methods.
> 
> This mistake reminded of how people in this group (maybe not you in
> particular) happily accept the terms "instance method" and "class
> method" HOWEVER if you _dare_ use the terms "instance variable" or
> "class variable" you get a swift rebuke.
> 
> Would anyone care for another serving of logically inconsistent py?

Rick, what makes you think that this is logically inconsistent?

"Method" is the accepted name for functions attached to classes. They 
report themselves as "methods":

py> class Test(object):
... def spam(self):
... pass
...
py> Test().spam
>

There are two built-ins for creating different types of method: the 
classmethod and staticmethod functions. If you don't think that these 
objects should be called " method", then what do you think 
that they should be called?

On the other hand, the terms "instance variable" and "class variable" are 
logically inconsistent with other terminology. It is common practice, 
across dozens or hundreds of languages, to refer to variables by their 
type (either as declared, in static-typed languages like C or Haskell, or 
as they are expected to hold a value in dynamic languages like Ruby and 
Python):

- an integer variable is a variable used to hold an integer;
 
- a string variable is a variable used to hold a string;

- a float variable is a variable used to hold a float; 

- a boolean variable is be a variable used to hold a boolean; 

- for consistency, a class variable should be a variable used to 
  hold a class, e.g.:

  classes = [bool, float, MyClass, Spam, Ham, AnotherClass]
  for cls in classes:  # cls is a "class variable"
  print "The name of the class is", cls.__name__

- and similarly for consistency an instance variable should be a
  variable holding some arbitrary instance. Since everything in an
  instance in Python, this last one is too general to be useful.


Unfortunately people coming to Python from certain other languages, 
particularly Java, (mis)use "class variable" to mean something completely 
different:

- a class variable is a member attached to a class, and therefore 
  shared across all instances, what Python users usually call a 
  "class attribute";

- an instance variable is a member attached to an instance, and 
  therefore *not* shared across instances, what Python users usually
  call an "instance attribute" or even just "attribute".


As I see it, it is not Python being inconsistent. What do you consider is 
inconsistent by *avoiding* the use of "class variable" to mean an 
attribute or member attached to a class?


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-25 Thread Rick Johnson
On Tuesday, December 25, 2012 3:08:21 PM UTC-6, Dennis Lee Bieber wrote:
> Only that many of us don't believe Python has /variables/, the use
> of instance/class as a modifier is thereby moot.

What IS a variable Dennis?
#

#Variable (ComputerScience)#

# In computer programming, a variable is a storage #
# location and an associated symbolic name (an identifier) #
# which contains some known or unknown quantity or #
# information, a value. The variable name is the usual way #
# to reference the stored value; this separation of name   #
# and content allows the name to be used independently of  #
# the exact information it represents. [...] The   #
# identifier in computer source code can be bound to a #
# value during run time, and the value of the variable may #
# thus change during the course of program execution.  #

#
With that accurate definition in mind you can now understand how Python classes 
CAN and DO have variables, just as Python modules have variables; psst: they're 
called "global variables"!

Now, whilst i don't believe we should haphazardly re-define the definition of 
CS terms (or worse, re-invent the wheel by inventing new terms when perfectly 
good terms exist) I DO believe we should interpret these terms in their current 
context.

For instance, Python has no REAL "global variables", so we can happily refer to 
module level variables as global variables. However in many other languages 
(like Ruby for instance) we can declare REAL "global variables" that are known 
across all namespaces. And since Ruby also has modules which /themselves/ can 
contain variables, we would refer to "module level variables" as "module 
variables". 

> An instance method is a method that works on an instance of the
> class, whereas a class method is meant to work on the class as a
> whole

Allow me to use better terms:

  An instance method is a method that is known to an
  instance of the class only, whereas a class method is
  known to all instances and accessible from the class
  identifier

Now with that clear description in mind, apply it to variables:

  An instance method is a method that is known to an
  instance of the class only, whereas a class method is known
  to all instances and accessible from the class identifier.

This transformation is without flaw because it is based on logic and not 
emotion.

> ...I don't know of anyone arguing that Python does not have
> "methods".

Of course not because they would have to be insane. However, we should never 
adopt illogical terms just because a few folks cannot resolve the definition of 
the proper terms.
-- 
http://mail.python.org/mailman/listinfo/python-list


regarding compiling the Python 2.7 and 3.3 with mingw

2012-12-25 Thread ginzzer
Hi all, 
  For some reason, I have to develop my software with mingw under windows. 
First of all, I need python installed in the msys but I try all my ways to 
install 2.6.x, 2.7.x, 3.2.x and 3.3.0, no one succeed. I search all issues and 
google the related information online, it seems that it doesn't support python 
on mingw? But what stranger is there are a few posts here with the patch 
presented, so is there any way to make the source compiled in mingw? I try all 
the available patches but again, it didn't solve the problem. Here are the 
error messages when I try to compile the 3.3.0 in mingw, 

  ./configure  ---> no problem
  make ---> errors shown below
  Objects/exceptions.c:2527:5: error: 'EALREADY' undeclared (first use in this 
function)
  Objects/exceptions.c:2527:5: note: each undeclared identifier is reported 
only once for each function it appears in
  Objects/exceptions.c:2528:5: error: 'EINPROGRESS' undeclared (first use in 
this function)
  Objects/exceptions.c:2529:5: error: 'EWOULDBLOCK' undeclared (first use in 
this function)
  Objects/exceptions.c:2532:5: error: 'ESHUTDOWN' undeclared (first use in this 
function)
  Objects/exceptions.c:2536:5: error: 'ECONNABORTED' undeclared (first use in 
this function)
  Objects/exceptions.c:2538:5: error: 'ECONNREFUSED' undeclared (first use in 
this function)
  Objects/exceptions.c:2540:5: error: 'ECONNRESET' undeclared (first use in 
this function)
  Objects/exceptions.c:2557:5: error: 'ETIMEDOUT' undeclared (first use in this 
function)
  make: *** [Objects/exceptions.o] Error 1

I then try compiling the version 2.7.3, different errors were shown while 'make'

  ./Modules/posixmodule.c:6151:5: warning: implicit declaration of function 
'wait'[-Wimplicit-function-declaration]
  ./Modules/posixmodule.c: In function 'posix_fdopen':
  ./Modules/posixmodule.c:6751:9: warning: implicit declaration of function 
'fcntl' [-Wimplicit-function-declaration]
  ./Modules/posixmodule.c:6751:27: error: 'F_GETFL' undeclared (first use in 
this function)
  ./Modules/posixmodule.c:6751:27: note: each undeclared identifier is reported 
only once for each function it appears in
  ./Modules/posixmodule.c:6753:23: error: 'F_SETFL' undeclared (first use in 
this function)
  ./Modules/posixmodule.c: In function 'posix_pipe':
  ./Modules/posixmodule.c:6816:5: warning: implicit declaration of function 
'pipe' [-Wimplicit-function-declaration]
  ./Modules/posixmodule.c: At top level:
  ./Modules/posixmodule.c:671:1: warning: 'posix_fildes' defined but not used 
[-Wunused-function]
  ./Modules/posixmodule.c:7480:1: warning: 'conv_confname' defined but not used 
[-Wunused-function]
  ./Modules/posixmodule.c:8387:1: warning: 'setup_confname_table' defined but 
not used [-Wunused-function]
  make: *** [Modules/posixmodule.o] Error 1

I highly appreciate it if you could show me any hints in compiling the
python in mingw.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Help] [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-25 Thread Rick Johnson
On Tuesday, December 25, 2012 4:56:44 PM UTC-6, Steven D'Aprano wrote:

> Rick, what makes you think that this is logically inconsistent?
> "Method" is the accepted name for functions attached to classes. They
> report themselves as "methods":
> [...]
> There are two built-ins for creating different types of method: the
> classmethod and staticmethod functions. If you don't think that these
> objects should be called " method", then what do you think
> that they should be called?

I'm  not arguing about against instance method/class method name convention, i 
am talking about instance variable/class variable; pay attention!

> On the other hand, the terms "instance variable" and "class variable" are
> logically inconsistent with other terminology. It is common practice,
> across dozens or hundreds of languages, to refer to variables by their
> type

Variable have no "type", only the value of variable has a "type". 

> (either as declared, in static-typed languages like C or Haskell, or
> as they are expected to hold a value in dynamic languages like Ruby and
> Python):
>
> - an integer variable is a variable used to hold an integer;
> - a string variable is a variable used to hold a string;
> - a float variable is a variable used to hold a float;
> - a boolean variable is be a variable used to hold a boolean;
> - for consistency, a class variable should be a variable used to
>   hold a class, e.g.:
>   classes = [bool, float, MyClass, Spam, Ham, AnotherClass]
>   for cls in classes:  # cls is a "class variable"
>   print "The name of the class is", cls.__name__
> - and similarly for consistency an instance variable should be a
>   variable holding some arbitrary instance. Since everything in an
>   instance in Python, this last one is too general to be useful.

Your "last one"(sic) comment negates your whole argument of referring to 
variables by what type the variable references. Since EVERYTHING is an obj then 
ALL variables should be termed "instance variables" (that's going by your logic 
of course).

> Unfortunately people coming to Python from certain other languages,
> particularly Java, (mis)use "class variable" to mean something completely
> different:

Don't try to confuse us with your illogical ways, Lord Steven. Your sad 
devotion to that ancient hatred of java has not helped you conjure up logical 
terminology, or given you enough clairvoyance to find the truth...
-- 
http://mail.python.org/mailman/listinfo/python-list


Simple audio library

2012-12-25 Thread Abhas Bhattacharya
Which simple python audio library will you suggest for low level audio creation 
(for eg I want to create tones of different intensities and frequency 
continously and then record the whole sequence)? (Although a minimal audio 
library is ok, it would be better if you can tell me about a full-fledged audio 
library along with low level access)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding the name of a function while defining it

2012-12-25 Thread Roy Smith
In article ,
 Abhas Bhattacharya  wrote:

> While I am defining a function, how can I access the name (separately as 
> string as well as object) of the function without explicitly naming 
> it(hard-coding the name)?
> For eg. I am writing like:
> def abc():
> #how do i access the function abc here without hard-coding the name?

Do you need it at compile-time, or is it good enough to have the name a 
run-time?  Assuming the latter, then I'm thinking the traceback module 
is your friend.  Call traceback.extract_stack() and pull off the last 
frame in the stack.  The function name will be in there.

There may be a cleaner way, but that's what I've done in the past.

I've only ever wanted the name.  If you need the actual function object, 
I suppose you might eval() the name, or something like that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Newbie] Require help migrating from Perl to Python 2.7 (namespaces)

2012-12-25 Thread alex23
On 26 Dec, 09:42, Rick Johnson  wrote:
> Python classes CAN and DO have variables, just as Python modules
> have variables; psst: they're called "global variables"!

Actually, they're called "module attributes", but don't let the facts
get in the way of your little rant. You never have before.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Password hash

2012-12-25 Thread Ramchandra Apte
On Monday, 24 December 2012 08:08:12 UTC+5:30, Robert Montgomery  wrote:
> I am writing a script that will send an email using an account I set up
> 
> in gmail. It is an smtp server using tls on port 587, and I would like
> 
> to use a password hash in the (python) script for login rather than
> 
> plain text. Is this do-able? Details please.

No. The password is encrypted with TLS I think so I believe you shouldn't worry 
much about security.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple audio library

2012-12-25 Thread Xantipius
On Dec 26, 5:07 am, Abhas Bhattacharya 
wrote:
> Which simple python audio library will you suggest for low level audio 
> creation (for eg I want to create tones of different intensities and 
> frequency continously and then record the whole sequence)? (Although a 
> minimal audio library is ok, it would be better if you can tell me about a 
> full-fledged audio library along with low level access)

Check this list of packages: http://pypi.python.org/pypi
-- 
http://mail.python.org/mailman/listinfo/python-list


EOFError why print(e) cannot print out any information ?

2012-12-25 Thread iMath

why print(e) cannot print out any information ?

class user:
def __init__(self, x,y,z):
self.id = x
self.name = y
self.emailadd=z
def dispuser(self):
print('User ID: ', self.id)
print('User Name : ', self.name)
print('Email Address: ', self.emailadd)

f = open('UsersInfo.bin', 'wb')
n=int(input('How many users?'))
print('Enter ', n, 'numbers')
for i in range(0,n):
u=input('User ID: ')
n=input('User Name: ')
e=input('Email Address: ')
usrobj=user(u,n,e)
pickle.dump(usrobj,f)
f.close()
print('\nInformation of the users is:')
f = open('UsersInfo.bin','rb')
while True:
try:
usrobj = pickle.load(f)
except EOFError as e:
print(e)
break
else:

usrobj.dispuser()
f.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: EOFError why print(e) cannot print out any information ?

2012-12-25 Thread Andrew Berg
On 2012.12.25 23:26, iMath wrote:
> why print(e) cannot print out any information ?
If you want to manipulate tracebacks, use sys.exc_info() and the
traceback module from the standard library. The logging module also
comes with an exception() function and an exception() method for Logger
objects that will log tracebacks.

http://docs.python.org/3/library/sys.html#sys.exc_info
http://docs.python.org/3/library/traceback.html
http://docs.python.org/3/library/logging.html

-- 
CPython 3.3.0 | Windows NT 6.2.9200
-- 
http://mail.python.org/mailman/listinfo/python-list


Command Line Progress Bar

2012-12-25 Thread Kevin Anthony
Hello,
I'm writing a file processing script(Linux), and i would like to have a
progress bar.  But i would also like to be able to print messages.  Is
there a simple way of doing this without implementing something like
ncurses?

-- 
Thanks
Kevin Anthony
www.NoSideRacing.com

Do you use Banshee?
Download the Community Extensions:
http://banshee.fm/download/extensions/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Command Line Progress Bar

2012-12-25 Thread Mitya Sirenef

On 12/26/2012 01:17 AM, Kevin Anthony wrote:

Hello,
I'm writing a file processing script(Linux), and i would like to have 
a progress bar.  But i would also like to be able to print messages. 
 Is there a simple way of doing this without implementing something 
like ncurses?


--
Thanks
Kevin Anthony
www.NoSideRacing.com 



Sure, you just need to print messages then the progress bar, without 
printing newline, then
sys.stdout.flush(), then in the next loop start by printing '\r' to 
erase the progress bar.


That is, if you want messages to scroll up. You can also use half a line 
for the progress
bar and the other half for a short message, then you print both with 
sys.stdout.flush()

and erase both with '\r'.

 - mitya


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

--
http://mail.python.org/mailman/listinfo/python-list


I am facing an issue while decoding json string using json.loads

2012-12-25 Thread sajuptpm

I am facing an issue while decoding json string using json.loads(jstring). Its 
working, if i do json.dumps(eval(jstring)) before json.loads(jstring). I could 
not figure out the issue. I want to avoide use of "eval" here.



## Failing without json.dumps(eval(jstring)) 


def format_json_string(self, jstring):
"""
"""
from pprint import pprint
print "===string before urllib.unquote===", pprint(jstring)
jstring = urllib.unquote(jstring)##For revert encode change applied in 
the javascript
print "===string after urllib.unquote===", pprint(jstring)
jstring = json.loads(jstring)
print "===string after json.loads(jstring) ===", pprint(jstring)




===string from client 
(javascript)u'{"selected_objects":{"datacenter-2":{"name":"Data 
!@#$%25^&*()_ {}[]|%5c%2f.,?><:\\"`Center8(Data !@#$%^&*()_ 
{}[]|/.,?><:\\"`Center8)","type":"Datacenter","moid":"datacenter-2","actual_name":"Data
 !@#$%25^&*()_ {}[]|%5c%2f.,?><:\\"`Center8","server_pools":[{"name":"cluster 
~!@#$%25^&*()_ {}|\\":?><,.%2f;\'%5c][=-`(cluster ~!@#$%^&*()_ 
{}|\\":?><,./;\'][=-`)","type":"ClusterComputeResource","moid":"domain-c401","actual_name":"cluster
 ~!@#$%25^&*()_ 
{}|\\":?><,.%2f;\'%5c][=-`","hosts":[{"name":"192.168.1.13","type":"HostSystem","moid":"host-27","actual_name":"192.168.1.13"}]}]}}}'
None



===string after 
urllib.unquoteu'{"selected_objects":{"datacenter-2":{"name":"Data 
!@#$%^&*()_ {}[]|\\/.,?><:\\"`Center8(Data !@#$%^&*()_ 
{}[]|/.,?><:\\"`Center8)","type":"Datacenter","moid":"datacenter-2","actual_name":"Data
 !@#$%^&*()_ {}[]|\\/.,?><:\\"`Center8","server_pools":[{"name":"cluster 
~!@#$%^&*()_ {}|\\":?><,./;\'\\][=-`(cluster ~!@#$%^&*()_ 
{}|\\":?><,./;\'][=-`)","type":"ClusterComputeResource","moid":"domain-c401","actual_name":"cluster
 ~!@#$%^&*()_ 
{}|\\":?><,./;\'\\][=-`","hosts":[{"name":"192.168.1.13","type":"HostSystem","moid":"host-27","actual_name":"192.168.1.13"}]}]}}}'
None
Traceback (most recent call last):
  File 
"/home/saju/cvt/tk/src/cct/web/cct/cct/controllers/VcenterController.py", line 
69, in import_managed_objects_from_vcenter
self.vcenter_service.validate_vcenter(session['auth'], vcenter_id, context)
  File "/home/saju/cvt/tk/src/cct/web/cct/cct/viewModel/VcenterService.py", 
line 360, in validate_vcenter
context = self.format_json_string(context)
  File "/home/saju/cvt/tk/src/cct/web/cct/cct/viewModel/VcenterService.py", 
line 747, in format_json_string
jstring = json.loads(jstring)
  File 
"/home/saju/cms/cct-enterprise/tg2env/local/lib/python2.7/site-packages/simplejson-2.5.0-py2.7-linux-x86_64.egg/simplejson/__init__.py",
 line 451, in loads
return _default_decoder.decode(s)
  File 
"/home/saju/cms/cct-enterprise/tg2env/local/lib/python2.7/site-packages/simplejson-2.5.0-py2.7-linux-x86_64.egg/simplejson/decoder.py",
 line 402, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File 
"/home/saju/cms/cct-enterprise/tg2env/local/lib/python2.7/site-packages/simplejson-2.5.0-py2.7-linux-x86_64.egg/simplejson/decoder.py",
 line 418, in raw_decode
obj, end = self.scan_once(s, idx)
JSONDecodeError: Invalid \escape: line 1 column 289 (char 289)




### Working with json.dumps(eval(jstring)) #



But, here i have to do json.dumps(eval(jstring)) before json.loads(). How to do 
it without eval ??? 



def format_json_string(self, jstring):
"""
"""
from pprint import pprint
print "===string from client (javascript)===", pprint(jstring)
jstring = urllib.unquote(jstring)##For revert encode change applied in 
the javascript
print "===string after urllib.unquote===", pprint(jstring)
jstring = json.dumps(eval(jstring))
print "===string after json.dumps(eval(jstring) ===", pprint(jstring)
jstring = json.loads(jstring)
print "===string after json.loads(jstring) ===", pprint(jstring)




===string from client 
(javascript)u'{"selected_objects":{"datacenter-2":{"name":"Data 
!@#$%25^&*()_ {}[]|%5c%2f.,?><:\\"`Center8(Data !@#$%^&*()_ 
{}[]|/.,?><:\\"`Center8)","type":"Datacenter","moid":"datacenter-2","actual_name":"Data
 !@#$%25^&*()_ {}[]|%5c%2f.,?><:\\"`Center8","server_pools":[{"name":"cluster 
~!@#$%25^&*()_ {}|\\":?><,.%2f;\'%5c][=-`(cluster ~!@#$%^&*()_ 
{}|\\":?><,./;\'][=-`)","type":"ClusterComputeResource","moid":"domain-c401","actual_name":"cluster
 ~!@#$%25^&*()_ 
{}|\\":?><,.%2f;\'%5c][=-`","hosts":[{"name":"192.168.1.13","type":"HostSystem","moid":"host-27","actual_name":"192.168.1.13"}]}]}}}'
None



===string after 
urllib.unquote===u'{"selected_objects":{"datacenter-2":{"name":"Data 
!@#$%^&*()_ {}[]|\\/.,?><:\\"`Center8(Data !@#$%^&*()_ 
{}[]|/.,?><:\\"`Center8)","type":"Datacenter","moid":"datacenter-2","actual_name":"Data
 !@#$%^&*()_ {}[]|\\/.,?><:\\"`Center8","server_pools":[{"name":"cluster 
~!@#$%^&*()_ {}|\\":?><,./;\'\\][=-`(clu