python without OO
Is it possible to write purely procedural code in Python, or the OO constructs in both language and supporting libraries have got so embedded that it's impossible to avoid them? Also, is anyone aware of any scripting language that could be considered as "Python minus OO stuff"? (As you can see I'm completely new to Python and initially believed it's a nice&simple scripting language before seeing all this OO stuff that was added in over time) Thanks, Davor -- http://mail.python.org/mailman/listinfo/python-list
Re: python without OO
Thanks, I do not hate OO - I just do not need it for the project size I'm dealing with - and the project will eventually become open-source and have additional developers - so I would prefer that we all stick to "simple procedural" stuff rather than having to deal with a developer that will be convincing me that his 50 layers inheritance hierarchy is good since it exists in some weird pattern that he saw somewhere on some Java design patterns discussion board :-) and other "proper" OO design issues... Once I opted for C++ in a very small project and believed everyone will stick with C subset + better type checking offered through C++ - but I simply could not manage to keep them off using OO stuff which was just making program more complicated than it should have been. (note, I am not an experienced developer, nor the others I'll be working with (even though some think they are:-)), so I prefer preemptively dealing with issue of everyone showing off their OO design skills) Davor -- http://mail.python.org/mailman/listinfo/python-list
Re: python without OO
On the other hand, this does beggar for a reason to bother with Python at all. It seems you could be happy doing BASH scripts for Linux or DOS batch files for Windows. Both are "nice&simple" scripting languages free of object oriented contamination. not really, what I need that Python has and bash&dos don't is: 1. portability (interpreter runs quite a bit architectures) 2. good basic library (already there) 3. modules for structuring the application (objects unnecessary) 4. high-level data structures (dictionaries & lists) 5. no strong static type checking 6. very nice syntax so initially I was hoping this is all what Python is about, but when I started looking into it it has a huge amount of additional (mainly OO) stuff which makes it in my view quite bloated now... anyhow, I guess I'll have to constrain what can be included in the code through different policies rather than language limitations... Thanks Davor -- http://mail.python.org/mailman/listinfo/python-list
Re: python without OO
M.E.Farmer wrote: Wrap your head around Python, don't wrap the Python around your head! This is NOT Java, or C++ or C , it IS Python. that's interesting hypothesis that behavior will vary due to the use of different language - actually most python scripts that I have seen do not even use OO which is quite understandable (same with perl, php,..) and I'm not even sure why all these languages have incorporated OO at all... (note, I am not an experienced developer, nor the others I'll be working with (even though some think they are:-)) Don't worry we didn't get confused, it was quite clear ;) :-) Also you are telling me you don't have an OO problem, you have a problem with your managment and communication skills. yeah, it's really tough telling them to write code so I can understand it without having to know about all these patterns of theirs. Davor -- http://mail.python.org/mailman/listinfo/python-list
Re: python without OO
M.E.Farmer, first to clarify few things - I'm neither manager nor professionally involved in code development - I'm just embarking on a small project that I would like to attract some programmers to later on and make it a nice open-source system. Based on my previous experience with few SMALL projects, I would like to avoid object orientation as much as possible. The reason is that I always ended up working with people who were without much experience, same as me, but they were all so influenced by OO propaganda that it was impossible to reason with them and to go with as simple solution as possible (not saying that OO solution is necessarily more complex than a structured one IN ALL CASES - but in any single case I've seen so far it was). So every single time I was wasting time trying to explain why not to go with cool OO way as opposed to simple un-cool structured solution. So, if the application was feasible to develop in C or C++, the solution would be easy - just choose C and avoid all OO mess - of course would have slightly more problems with C's looser type-checking but in my experience it's far less problem then troubles that happen when one starts going crazy with C++ generic classes, multiple inheritance, deep inheritance trees, etc.. The nature of the application that I'm planning on is perfectly suited to a good high-level scripting language, and python looked very attractive so I decided to take look at it, but then i realized it has all this OO stuff that I got scared off immediately :-) - luckily some of these other guys including yourself mentioned that there are not that many issues with Python's OO stuff as there is with Java's of C++ (seems I'm not the only one with Java&C++ OO traumas :-)) - so I'm encouraged to proceed with Python. > It seems you are telling me that : > 1) You do not understand most programming concepts not really - I rather want to prevent incorporation of anything that is not really needed in the code... > 2) You are not willing to learn. more that I like to reject anything that is not obviously substantiated and that many people seem to have problems with... > 3) You might not have the skill set to manage developers maybe not good management approach but I would always opt for "not giving them the tools I don't want them to use" over "giving them tools I don't want them to use and then forbidding them to use these tools" - especially if they are not getting paid for what they are building :-) > Stop telling your programmers how to program! Seriously NOW. > If you managed a group of doctors would you tell them that they could > only use techniques that *YOU* understood, even if the were STANDARD > and well known by others? This sounds like one of those ideas preached by agile community - I say set up the rules and conventions as much as you can (in a *non-intrusive* way) if you are a manager... Exactly the group of professionals you mentioned in your example is support for what I am claiming. In fact in that profession everything is exactly about the rules, precise techniques, and exact processes that have to be done and when they have to be used. If anything gets done outside of recommended practices they are legally responsible for. For example, if a person has to undergo sinus surgery and the endoscopic version is sufficient (simple, non-intrusive, internal incision) and a doctor decides to do the traditional surgery with external cutting - I guess everyone would be pissed off - especially the patient :-).. Also, yes, I have read GOF book... but I never found it a big deal - no one ever had to document structured patterns - which definitely exist - but seem to be obvious enough that there is no need to write a book about them... Thanks for your feedback! Davor -- http://mail.python.org/mailman/listinfo/python-list
Re: python without OO
thanks for the link > know what's funny: in the Lua mailing list there is currently a > discussion about adding OO to Lua. I guess most of these newer languages have no choice but to support OO if they want to attract a larger user base :-(... davor -- http://mail.python.org/mailman/listinfo/python-list
Re: python without OO
Timo Virkkala wrote: This guy has got to be a troll. No other way to understand. not really - it was not my intention at all - but it seems people get upset whenever this OO stuff is mentioned - and what I did not expect at all at this forum as I believed Python people should not be so OO hardcore (seems not all as quite a few have indicated in their replies)... Nevertheless, I think the discussion has several quite good points! -- http://mail.python.org/mailman/listinfo/python-list
Re: python without OO
I'd like to thank everyone for their replies. The main important lesson I got is: Python does not have that many issues with misuse of OO as compared to Java/C++ because it's *dynamically* typed language and extremely powerful *dictionary* data structure. I browsed docs a bit today, and they also confirm what I have believed - that OO is totally secondary in Python. In fact, object/classes/metaclasses are nothing but *dictionaries with identity* in python. Love this approach. In fact, you can very easily implement your own *OO model* completely separate of Python's OO model... Now I actually strongly believe that Python's author has introduced the whole OO model just to attract and make happy OO population... In fact, *Python's dynamic type checking mechanisms + dictionary is way more powerful than Java/C++'s static type checking mechanisms + their OO mechanisms* and you can definitely be more productive using Python's structured programming than Java/C++ OO programming :-)... and Python is probably the best example why we should have skipped OO all together.. --- second, instead of playing with OO plagued design principles do as follows: 1. separate data, functionality, and structure from each other as much as you can (in Python only valid structural element I've seen so far is module - ignore objects & classes!) 2. do not assume any have identity (even if the underlying language model provides and uses one) - so don't pass them around and crazy stuff... so you get a nice program with separate data structures and functions that operate on these data structures, with modules as containers for both (again ideally separated). Very simple to do and maintain no matter what OO preachers tell you... Davor -- http://mail.python.org/mailman/listinfo/python-list
convert .pdf files to .txt files
Hi, my name is david. I need to read information from .pdf files and convert to .txt files, and I have to do this on python, I have been looking for libraries on python and the pdftools seems to be the solution, but I do not know how to use them well, this is the example that I found on the internet is: from pdftools.pdffile import PDFDocument from pdftools.pdftext import Text def contents_to_text (contents): for item in contents: if isinstance (item, type ([])): for i in contents_to_text (item): yield i elif isinstance (item, Text): yield item.text doc = PDFDocument ("/home/dave/pruebas_ficheros/carlos.pdf") n_pages = doc.count_pages () text = [] for n_page in range (1, (n_pages+1)): print "Page", n_page page = doc.read_page (n_page) contents = page.read_contents ().contents text.extend (contents_to_text (contents)) print "".join (text) the problem is that on some pdf´s it generates join words and In spanish the "acentos" in words like: "camión" goes to --> cami/86n or "IMPLEMENTACIÓN" -> "IMPLEMENTACI?" give strange characters if someone knows how to use the pdftools and can help me it makes me very happy. Another thing is that I can see the letters readden from .pdf on the screen, but I do not know how to create a file and save this information inside the file a .txt Sorry for my english. Thanks for all. -- http://mail.python.org/mailman/listinfo/python-list
Re: convert .pdf files to .txt files
Thanks for all you wrote, It will be very usefull to me, at the end I use that code and the file I introduce is converted to .txt on the directory where the file is placed, and in documents written in spanish this do not gives problems on "acentos" in words like "camión" or "introducción" that was very important to me. Thanks! import os os.system("pdftotext -layout my_pdf_file.pdf") #This will create 'my_pdf_file.txt' file. -- http://mail.python.org/mailman/listinfo/python-list
comparing two lists
i have two lists list1 = ['01:15', 'abc', '01:15', 'def', '01:45', 'ghi' ] list2 = ['01:15', 'abc', '01:15', 'uvz', '01:45', 'ghi' ] and when I loop through the list list_difference = [] for item in list1: if item not in list2: list_difference.append(item) and I managed to get the difference, but I need time as well because it is a separate item and 'uvz' does not mean to me anything in the list with a few thousand entries. I tried to convert it to the dictionary, but it overwrites with last key:value {'01:15' : 'def'} -- https://mail.python.org/mailman/listinfo/python-list