I finally discovered how cool github is, and have started putting some code up there. My first entry is Record.py. I'm calling it the cure to the bane of __init__" because
- Mutable data structures are a bane to concurrent (multi-threaded) code.
- Writing self.foo = foo, self.bar = bar, etc, is a huge waste of time.
- When you have lots of data structures in memory, tuple-based data uses 1/4 the memory of class-based data.
So, go to the github repo or use it by following the really easy steps:
- Download Record.py from http://github.com/pthatcher/pyrec/blob/master/Record.py
- put from Record import Record at the top of your code.
- make a class by saying something like class Person(Record("name", "age"))
- Never write __init__ again (unless you want mutability).
Update: A commenter (thanks Dan!) pointed out that this is a lot like namedtuple, added in python 2.6. He asked why use this instead of namedtuple. Well, I have to admit that I probably would have never created pyrec if namedtuple existed 3 years ago. I try to avoid NIH syndrome. But it didn't exist, so I wrote pyrec. But I've been using pyrec for three years, so I have some experience on some little things that make a big difference (to me). Here are a few advantages pyrec has over namedtuple:
- It has a nicer interface. I prefer new(val1, val2) to _make([val1, val2]), alter to _update, and class Person(Record("name", "age")) to Person = namedtuple("Person", "name, age")
- I added the setField methods. That's what I use 90% of the time. Only about 10% of the time do I use alter. setField is a lot more convenient.
- With pyrec, you can safely override __iter__ and __getitem__. For example, in Record.py, you'll see the implementation of a LinkedList. I tried doing that with namedtuple, but the overidden __getitem__ clobers the name lookup and __iter__ the tuple unpacking. You can use tuple.__iter__(rec) to get around the latter, but pyrec's .values is a lot nicer.
- pyrec has .namedValues for ordered (field, value) pairs, unlike _asdict() which throws out the order. For many things I use pyrec for, this matters.
- You can improve it! Have looked at the code for namedtuple? Ugly. This is pretty clean, so you can improve it very easily if you need additional functionality which will work with all of your records.
Is there a compelling reason to prefer pyrec to collections.namedtuple? The latter is part of the standard library in versions 2.6 and above, and works just fine in 2.5.
ReplyDeleteEither way, death to mutability-by-default!
IEEE Final Year projects Project Centers in India are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Projects for CSE It gives you tips and rules that is progressively critical to consider while choosing any final year project point.
DeleteJavaScript Online Training in India
JavaScript Training in India
The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training
Dan, I updated the post to answer your question. Thanks for brining it up. I'm still in python 2.5 land and had forgotten about additions to 2.6 like namedtuple.
ReplyDeleteThanks for the comprehensive reply. pyrec's interface definitely looks nicer, particularly the support for overriding __getitem__ - namedtuple fails rather ungracefully in that department. I'll have to give a pyrec a spin.
ReplyDeleteInteresting.
ReplyDeleteOne point: setField instead of set_field:
1) conflicts with PEP 008
2) breaks capitalization, breaks consistency. You know, attribute name is 'foo', setter is 'setFoo'.
I'm using this:
class Record(dict): pass
foo = Record(g=50)
If you change dict to FrozenDict, it will become immutable. But tuples take less memory, yeah.
P.S.: "Your HTML cannot be accepted: Tag is not allowed: CODE" What's wrong with the most useful tag? And it doesn't accept PRE either. Jesus, even Q is not allowed.
Temoto, good point about the method names. PEP008 specifically says:
ReplyDelete"mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility."
I've been using mixedCase for all of my code for years because of "prevailing style". And I forgot that most python developers use underscore_case.
So, in order to fix this, I've changed pyrec from mixedCase to underscore_case go see it at http://github.com/pthatcher/pyrec. Thanks for the heads-up.
Your article is very good and useful, thank you very much for this content. : see more
ReplyDeleteشركة قمة الدقة للخدمات المنزلية
ReplyDeleteشركة الماسة لمكافحة الحشرات بالخبر
شركة تنظيف مجالس بالخبر
I like the post format as you create user engagement in the complete article. It seems round up of all published posts. Thanks for gauging the informative posts.
ReplyDeletecara menggugurkan kandungan
obat aborsi
kalkulator kehamilan
tanda tanda kehamilan
شركة رش مبيدات بالدمام
ReplyDeleteشركة مكافحة حشرات بالدمام
شركة مكافحة النمل الابيض بالدمام
شركة مكافحة الفئران والقوارض بالدمام
شركة مكافحة صراصير بالدمام
شركة مكافحة البق بالدمام
شركة رش دفان بالدمام
شركة مكافحة ثعابين بالدمام
شركة رش مبيدات بالدمام
ReplyDeleteشركة مكافحة حشرات بالدمام
شركة مكافحة النمل الابيض بالدمام
شركة مكافحة الفئران والقوارض بالدمام
شركة مكافحة صراصير بالدمام
شركة مكافحة البق بالدمام
شركة رش دفان بالدمام
شركة مكافحة ثعابين بالدمام
شركة رش مبيدات بالدمام
ReplyDeleteشركة مكافحة حشرات بالدمام
شركة مكافحة النمل الابيض بالدمام
شركة مكافحة الفئران والقوارض بالدمام
شركة مكافحة صراصير بالدمام
شركة مكافحة البق بالدمام
شركة رش دفان بالدمام
شركة مكافحة ثعابين بالدمام
ReplyDeleteشركة غسيل خزانات بالمدينة المنورة و عمال مروبون وحاصلون على شهادة صحية فقط اتصل بنا لتحصل على افضل خدمة غسيل خزانات
Thanks for interesting blog
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteYou want to tell the story a month ago I found this site and at first nothing worked out for me and then I thought of everything and now I spend all my free time on this site ravishing new online casino Do everything meaningfully and you will succeed
ReplyDeleteNice Blog, thank you so much for sharing such an amazing information with us.
ReplyDeleteWebsite Designing Company in Delhi
Thank You! For sharing such a great article, It’s been a amazing article.
ReplyDeleteIt’s provide lot’s of information, I really enjoyed to read this.
pvc laminates sheet manufacturer india
ReplyDeletepvc laminates sheet supplier in india
pvc laminates sheet
pvc laminates sheet exporter in india
bendable pvc sheet
pvc laminates sheet price
pvc sheet suppliers in haryana
bendable pvc laminates india
bendable plastic sheet in india
meraki flexible pvc sheet
flexible pvc sheet suppliers
leminated plastic sheet india
pvc coated sheets india
flexible pvc sheets india
LAMINATEd texture sheets in india
LAMINATEd marble sheets in india
biggest indian manufacturer of pvc laminates
unicore pvc laminates
Interior Design Firm Delhi NCR
ReplyDeleteInterior Design Company in Noida
Interior Design Firm Noida
Interior Design Company In Delhi NCR
Top Interior Designer in Noida
Top 10 Interior Designer in Noida
Top 10 Interior Designer in Indrapuram
residential interior designer Delhi NCR
best interior designer in noida
interior design firm in delhi ncr
interior design firm delhi ncr
interior design company in noida
interior design company noida
interior design service in faridabad
best office interior decorators in noida
best office interior designers noida
best leather manufacturers in india
ReplyDeletetop leather products manufacturers in india
leather goods supplier in India
aviation leather manufacturers in india
Synthetic leather manufacturer in India
Synthetic leather manufacturing company India
Synthetic leather supplier Delhi
leather footwear supplier in India
footwear manufacturing company in India
car seat cover manufacturers in india
leather garments manufacturers in india
leather garments designer in india
Leather bags manufacturer in Delhi
Bali Honeymoon Packages From Delhi
ReplyDeleteBali Honeymoon Packages From Chennai
Hong Kong Packages From Delhi
Europe Packages from Delhi
Bali Honeymoon Packages From Bangalore
Bali Honeymoon Packages From Mumbai
Maldives Honeymoon Packages From Bangalore
we have provide the best fridge repair service.
ReplyDeletefridge repair in faridabad
LG Fridge Repair in Faridabad
Videocon Fridge Repair in Faridabad
Whirlpool Fridge Repair in Faridabad
LG Refrigerator Repair In Faridabad
we have provide the best ppc service.
ReplyDeleteppc company in gurgaon
website designing company in Gurgaon
PPC company in Noida
Rice Bags Manufacturers
ReplyDeletePouch Manufacturers
Nice blog, you put valuable information in your blog. I’m really thankful to you for sharing this blog with us. Ogen Information is one of the best Website Designing Company in Delhi.
ReplyDeleteWebsite Designing Company in Delhi
Your content in this blog is really impressive, I’m really thankful to you for this information. Visit Y&H Cargo for Shipping and Freight Forwarding Services.
ReplyDeleteLogistics Company in Delhi
I feel happy about and learning more about this topic. keep sharing your information regularly for my future reference. This content creates new hope and inspiration within me. Thanks for sharing an article like this. the information which you have provided is better than another blog.
ReplyDeleteBest IELTS Coaching institute in Dwarka
Best IELTS Coaching centre in Dwarka
Nice blog, get Fleet Painting and Vinyl Signage Printing Service by Kalakutir Pvt Ltd.
ReplyDeleteFleet Painting
ReplyDeleteهل تبحث عن شركة متخصصة فى خدمات التنظيف بالدمام بافضل المعدات والسوائل وثقة تمة فى العمل ودقة فى النتائج كل هذه المميزات توفرها شركة الجنرال الشركة الافضل والامثل فى الخدمات المنزلية بالدمام وبما اننا الشركة الافضل والامثل بدون منافس سوف نسعى لتوفر افضل الخدمات باقل تكلفة وبقدر كبير من الاهتمام والدقة عزيزى اينما كنت فى اى منطقة ا وحى تابع لمدينة الدمام اتصل بنا وسوف نصلك فى الحال شركة االجنرال للخدمات المنزلية
شركة نقل عفش بالدمام
شركة تسليك مجاري بالدمام
شركة مكافحة حشرات بالدمام
شركة تنظيف منازل بالدمام ومجالس وكنب وشقق
شركة مكافحه نمل ابيض بالدمام بافضل المبيدات
شركة تنظيف مجالس وكنب بالدمام بافضل مواد التنظييف
شركة تنظيف خزانات بالدمام مع التعقيم والغسيل
شركة تنظيف سجاد بالدمام بالبخار
شركة تنظيف شقق بالدمام وفلل وقصور
now present in your city
ReplyDeleteMobile app development company in mumbai
ReplyDelete
ReplyDeleteشركة تركيب غرف نوم بالمدينة المنورة
تعتبر شركة تركيب غرف نوم بالمدينة المنورة من كبرى الشركات التي تساعد الكثيرون في عمليات فك وتركيب غرف النوم، فمن الصعب على العملاء أن يقوموا بمثل هذه الأعمال لأنها تحتاج إلى متخصصون لديهم القدرة الفائقة في تركيب غرف النوم بمختلف أنواعها وأحجامها، ومن ضمن الكوادر التي تعتمد عليها شركة تركيب غرف نوم نجار بالمدينة المنورة المنورة فهم من العاملين بالشركة والتي تعتمد عليهم بشكل كبير في تنفيذ مثل هذه الأعمال الصعبة والتي تحتاج إلى أشخاص ذات خبرة طويلة وكبيرة في هذا المجال، كما أن شركة تركيب غرف نوم بالمدينة المنورة تقدم معدات وأدوات حديثة تساعد على تسهيل عملية تركيب غرف النوم والانتهاء في وقت وجيز ولا تحتاج هذه العملية إلى لإثنان فقط من عمال شركتنا الهمام.
PPC Service in Delhi
ReplyDeletePPC Companies in Delhi
SEO Company in Delhi
SEO Company in Delhi NCR
SMO Company in Delhi
SMO Company in India
Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. You’re doing a great job Man,Keep it up.
ReplyDeletestudy in canada
ielts coaching in gurgaon
Thank you so much dear for sharing such an amazing blog with us.
ReplyDeleteWebsite Designing Company in India
Nice blog, get an amazing Detective Services by Gribety Detective India in Jaipur and Bhopal.
ReplyDeleteDetective Agency in Jaipur
Sarswati Enterprises provide the best Pilfer Proof Caps and Aluminum caps & Closures Machinery in Delhi, India.
ReplyDeletePilfer Proof Caps Making Machinery
Put more informative things on this blog page, and thanks for sharing this. Visit Noble IVF for best Fertility treatment in Aligarh, India.
ReplyDeleteIVF Centre in Aligarh
Thank you so much dear for sharing such an amazing blog with us.
ReplyDelete247developers.com/seo-service-pakistan
Thanks for sharing your wealthy information. This is one of the excellent posts which I have seen. I have gone through all of your blogs, but this blog is the best one. I hope in future you will continue sharing such an excellent post. To know more visit: Mobile App Development Company usa
ReplyDeleteThis is the most supportive blog which I have ever observed.
ReplyDeleteJava Training in Bangalore
Ui Development Training in Bangalore
Indian Web Designers fast-growing website designing company in Delhi intend to create a website on your request according to your specifications.
ReplyDeleteWeb Design Company in Delhi
Digital Marketing company in india
Energy Saving Sensors Made by Highly Components Pvt. Ltd. - Which is the leading company in the field of Security related products in India. The company has achieved an unrivalled position in the market by introducing PIR Motion Sensors for automatic control of lights apart from other Security Sensors. Energy Saving Sensors in New Delhi
ReplyDeleteSmoke Alarm Sensor
Tekniko Global provides mobile app development company in noida for iPhone, iPad, Android, Blackberry & Windows 7 platforms including Xamarin for cross platform mobile development.
ReplyDeletemobile app development company in noida
Appslure is a high rated Mobile Game development company in Delhi. We are no 1 company for IOS & Android games.
ReplyDeleteGame Development company in Delhi
I thank you for the information and articles you provided
ReplyDeleteapp development company in delhi
ReplyDeleteI was not aware of such updating about the lesson but Now I am very excited to read this information and I hope this post will improve my teaching and writing ability
ReplyDeletebuy dissertation online uk
i am a beginner python learner so i was facing issue with mutable data structures being bane to concurrent code. thanks for sharing your experiments on record.py it has helped me alot.
ReplyDeletePut more informative things on this blog page. Clear basis concept and thanks for sharing this.
ReplyDeletePHP advancement is a well-known scripting language that is utilized to make intelligent and dynamic sites. Today, most business sites are made by utilizing php application development as it accompanies profoundly practical highlights and ease of use. So, organizations ready to make a customer's site with amazing information the executives highlights will require to recruit php development company. Our prime php website development improvement administrations start with understanding the client needs and stretches out to database driven top of the line custom undertaking web frameworks. Recruit devoted PHP engineers from Colan Infotech to plan php web development utilizing Photoshop, Flash etc. The php development India advancement administrations we offer are recorded underneath:
ReplyDeleteRead The Latest XXX Stories Now:
ReplyDeletexxx stories: Going Naked First-Time on a CamSite
The best php application development company in India. We contribute high quality custom php website development services from our well-trained team. Get to know more about the php development company in Chennai Reach us or just give a call to us for php development.
ReplyDeleteI found this one pretty fascinating, and you should go into my collection also. We provide Assignment help services all over the world. I am impressed with your article. We appreciate that please keep writing more content.
ReplyDeletecomputer science project help
Do my computer science assignment
computer science assignment help online
programming language assignment help
programming assignment help
computer programming assignment help
programming homework help
do my programming homework
coding assignment help
urgent programming assignment help
database management assignment help
database management homework help
java programming assignment help
java homework help
java programming homework help
java homework help online
java assignment help
java assignment help online
Thanks for sharing this information. I have shared this link with others to keep posting such information to provide the best in class assignment help online at very affordable prices.
ReplyDeletechemistry assignment help online
Criminal Law Assignment Help
Electrical Engineering Assignment Help
electrical engineering homework help
electrical engineering homework help
electrical engineering assignment
electrical assignment
electrical assignment help
electrical engineering homework
Geography Assignment Help
geography assignment
geography homework help
History Assignment Help
history homework helper
history homework help
help with history homework
homework help history
Columbus Day Pages
ReplyDeleteColumbus Day Gift Idea
Columbus Day Greetings
what day is columbus day 2020
Columbus Day jokes
Columbus day memes
Columbus day parades
Free Thanksgiving Images
ReplyDeleteHappy Thanksgiving GIF
happy blessed Thanksgiving 2020
Thanksgiving Cover Photos
Thanksgiving greetings images
Thanksgiving Prayer
Select the option of Assignment Help when you don’t want to take the stress of writing your assignments or homework. This option allows you to get experts’ assistance for composing your academic papers even in adverse conditions. You can take the online help of academic writers at any time using these kinds of services. If you can’t pay attention to homework writing or don’t have enough time, this option will help you a lot. Handle everything for composing your papers even in adverse conditions via online academic writing services.
ReplyDeleteHelp Assignment
Assignment Help Company
I am really very happy to visit your blog. Now I am found which I actually want. I check your blog every day and try to learn something from your blog. Please keep us up to date like this. Thanks for sharing.
ReplyDeleteAlso, we are giving 100% support after delivering the project. If you have any requirements regarding Blockchain, Iot, Ai, Travel Portal Development then you can contact us at +1 (415) 890 8990, +91 9500 069 296.
Travel Portal Development
Place an order for Assignment Help in Singapore so you can connect with professional writers. Pay a good amount to buy the services of online assignment help even in Singapore.
ReplyDeleteNeed Home Security System India for Home and Office, Contact DFS Services. Buy High Quality Home Security Intruder Alarm System or Burglar Alarm System, Video Doorbell and Security Cameras (IP Camera). Dfs Services is the best company for Home Security Systems in India.
ReplyDeletevisit us:-home security system Bangalore
security alarm
Merry Christmas Trees Wallpapers
ReplyDeletefamous Christmas poems
Christmas card greeting ideas
Funny Christmas Meme 2020
Merry Christmas Santa Claus Images
This is truly an practical and pleasant information for all. Thanks for sharing this to us
ReplyDeletebuy electronics online pakistan
Tejar is Pakistan’s top e-commerce store that deals in genuine and reliable consumer goods belonging to numerous brands and product categories.
Great content I love it Coursework Help Satta.
ReplyDelete