Sinisterly
Sweet Python Techniques and Advices. - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Python (https://sinister.ly/Forum-Python)
+--- Thread: Sweet Python Techniques and Advices. (/Thread-Sweet-Python-Techniques-and-Advices)

Pages: 1 2 3


RE: Sweet Python Techniques and Advices. - L0aD1nG - 08-13-2014

(08-13-2014, 08:09 PM)h3r0 Wrote: Great resource, there are a lot of little gems in there. Thank you.

(08-13-2014, 06:04 PM)l4ur15 Wrote: Thank you very much! That's what they don't teach you in books...

Thank you both for the feedback.
This thread will be updated soon again!


RE: Sweet Python Techniques and Advices. - L0aD1nG - 08-13-2014

(08-13-2014, 08:09 PM)h3r0 Wrote: Great resource, there are a lot of little gems in there. Thank you.

(08-13-2014, 06:04 PM)l4ur15 Wrote: Thank you very much! That's what they don't teach you in books...

Thank you both for the feedback.
This thread will be updated soon again!


RE: Sweet Python Techniques and Advices. - Psycho_Coder - 08-14-2014

(08-13-2014, 10:35 PM)L0aD1nG Wrote:
(08-13-2014, 05:53 PM)Psycho_Coder Wrote: for xml parsing use lxml its fast efficient and very user friendly

I am still using etree, I must check the others sometime. But still I find etree to be very clear.

EDIT: Does lxml.etree has a tostring() method that supports "pretty_print=True" as args?



Yes. Have a look : http://lxml.de/tutorial.html#the-e-factory

It has much more capabilities.


RE: Sweet Python Techniques and Advices. - Psycho_Coder - 08-14-2014

(08-13-2014, 10:35 PM)L0aD1nG Wrote:
(08-13-2014, 05:53 PM)Psycho_Coder Wrote: for xml parsing use lxml its fast efficient and very user friendly

I am still using etree, I must check the others sometime. But still I find etree to be very clear.

EDIT: Does lxml.etree has a tostring() method that supports "pretty_print=True" as args?



Yes. Have a look : http://lxml.de/tutorial.html#the-e-factory

It has much more capabilities.


RE: Sweet Python Techniques and Advices. - L0aD1nG - 08-14-2014

(08-14-2014, 07:14 AM)Psycho_Coder Wrote:
(08-13-2014, 10:35 PM)L0aD1nG Wrote:
(08-13-2014, 05:53 PM)Psycho_Coder Wrote: for xml parsing use lxml its fast efficient and very user friendly

I am still using etree, I must check the others sometime. But still I find etree to be very clear.

EDIT: Does lxml.etree has a tostring() method that supports "pretty_print=True" as args?



Yes. Have a look : http://lxml.de/tutorial.html#the-e-factory

It has much more capabilities.

Thank you sir, I will check it out some time!
Thanks for the recommendation!


RE: Sweet Python Techniques and Advices. - L0aD1nG - 08-14-2014

(08-14-2014, 07:14 AM)Psycho_Coder Wrote:
(08-13-2014, 10:35 PM)L0aD1nG Wrote:
(08-13-2014, 05:53 PM)Psycho_Coder Wrote: for xml parsing use lxml its fast efficient and very user friendly

I am still using etree, I must check the others sometime. But still I find etree to be very clear.

EDIT: Does lxml.etree has a tostring() method that supports "pretty_print=True" as args?



Yes. Have a look : http://lxml.de/tutorial.html#the-e-factory

It has much more capabilities.

Thank you sir, I will check it out some time!
Thanks for the recommendation!


RE: Sweet Python Techniques and Advices. - RiseAgainst03 - 08-15-2014

Thank you! Totally worth to know this.


RE: Sweet Python Techniques and Advices. - RiseAgainst03 - 08-15-2014

Thank you! Totally worth to know this.


RE: Sweet Python Techniques and Advices. - L0aD1nG - 09-05-2014

(09-05-2014, 09:40 PM)Venatori Wrote: Very good post here! These technique's will definitely help me in my future Python endeavors!

I do have one question though. What is the actual benefit from your "raw_input()" advice?

Thank you for your good words.

Well in python 2.x sys.stdin.readline() it proves to be a little faster when its about taking inputs from the user cause it avoids some automated things that which built-in raw_input() does (like for example the '\n' striping which in some case you might don't need it). Also its good to mention here that this 'problem' is claimed to be fixed on Python3.x versions and input() function.

For example if its about to take massive inputs and use raw_input inside a loop, if you want to achieve best performance available its prefferable to use sys.stdin.readline().
I made a simple sample run for you in ipython take a look...

Spoiler: Sample Image
[Image: Iol9ZDs.png]



Although that the difference is not big, its still a difference.
Plus the difference in time can vary depending on the task you have to solve.

I hope this helps.
Sincerely,
L0aD1nG


RE: Sweet Python Techniques and Advices. - Psycho_Coder - 09-06-2014

Hahaha you took that prettifyXMl code from my PINN modules that I shared Tongue hahaha okay no problem.