Re: Can post a code but afraid of plagiarism
On Thu, 23 Jan 2014 19:15:51 -0800, indar kumar wrote: > What if I want to search for a particular value inside the lists of all > keys except one that user inputs and also want to print that value. Then go right ahead and do so. You are learning Python, so this should be covered in your course. Did you follow the advice to work through the Python tutorial? http://docs.python.org/2/tutorial/ http://docs.python.org/3/tutorial/ depending on whether you are using Python 2 or 3. This is supposed to be your work, not ours. Start by writing down how you would solve this problem as a human being: for each key: if the key is the one the user inputted, skip this key otherwise: get all the lists for this key for each list: search for the value Now change that to Python code. Don't just ask us to solve the problem for you. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: SIngleton from __defaults__
thnx guys. On 24.01.2014 01:10, Terry Reedy wrote: Johannes Schneider Wrote in message: On 22.01.2014 20:18, Ned Batchelder wrote: On 1/22/14 11:37 AM, Asaf Las wrote: Chris is right here, too: modules are themselves singletons, no matter how many times you import them, they are only executed once, and the same module object is provided for each import. I'm not sure, if this is the whole truth. think about this example: cat bla.py a = 10 cat foo.py from bla import a This makes a a global in foo, bound to 10 def stuff(): return a This a refers to the global a in foo. cat bar.py from foo import stuff print stuff() a = 5 This bar.a is irrelevant to the behavior of stuff. print stuff() from bla import * print a python bar.py 10 foo.a == 10 10 foo.a == 10 10 bla.a == 10 here the a is coming from bla Twice and is known in the global namespace. There is no global namespace outside of modules. the value differs in stuff() No it does not. and before/after the import statement. foo.a does not change. bar.a is never used. So the instance of the module differs Nope. Each of the three module instances is constant. The bindings within each could change, but there are no rebinding in the code above. -- Johannes Schneider Webentwicklung [email protected] Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list
Re: generate De Bruijn sequence memory and string vs lists
Vincent Davis wrote: > Excellent Peter! > I have a question, the times reported don't make sense to me, for example > $ python3 -m timeit -s 'from debruijn_compat import debruijn_bytes as d' > 'd(4, 8)' > 100 loops, best of 3: 10.2 msec per loop > This took ~4 secs (stop watch) which is much more that 10*.0102 Why is > this? Look at the output, it's "100 loops" 100 * 10 msec == 1 sec together with "best of 3" you are already at 3 sec, minimum as it is the "best" run. Then, how do you think Python /knows/ that it has to repeat the code 10 times on my "slow" and 100 times on your "fast" machine? It runs the bench once, then 10, then 100, then 1000 times -- until there's a run that takes 0.2 secs or more. The total expected minimum time without startup overhead is then +calibration--+ +-measurement--+ (1 + 10 + 100) * 10msec + 3 * 100 * 10msec or about 4 secs. > $ python3 -m timeit -s 'from debruijn_compat import debruijn_bytes as d' > 'd(4, 11)' > 10 loops, best of 3: 480 msec per loop > This took ~20 secs vs .480*10 >>> .480*(1 + 10 + 3*10) 19.68 > d(4, 14) takes about 24 seconds (one run) This is left as an exercise ;) -- https://mail.python.org/mailman/listinfo/python-list
Re: generate De Bruijn sequence memory and string vs lists
Vincent Davis wrote: I plan to use the sequence as an index to count occurrences of sequences of length n. If all you want is a mapping between a sequence of length n and compact representation of it, there's a much simpler way: just convert it to a base-k integer, where k is the size of the alphabet. The resulting integer won't be any larger than an index into the de Bruijn sequence would be, and you can easily recover the original sequence from its encoding without needing any kind of lookup table. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
"Chris Angelico" wrote in message news:CAPTjJmokZUHta7Y3x_=6eujkpv2td2iaqro1su7nulo+gfz...@mail.gmail.com... > On Thu, Jan 23, 2014 at 8:16 AM, Asaf Las wrote: >> i am novice in python, but let me suggest you something: >> it would be beneficial to use json text file to specify >> your gui so composite data structure can be created using >> json and then your program can construct window giving >> its content will be based on simple text file? >> You can add every parameter to json encoded window system >> once your window construction will be using as interpreter >> for that. JSON is very structured and quite presentable for >> such kind of things. >> >> What Gurus do think about this suggestion? > > JSON is better than XML for that, but in my opinion, both are > unnecessary. Python code is easy to edit. (See [1] for more on Python > and XML.) When you're writing compiled code, it makes good sense to > drop out of code and use a simple text file when you can; but when > your code *is* a simple text file, why go to the effort of making a > JSON-based window builder? (Unless you already have one. GladeXML may > well be exactly what you want, in which case, go ahead and use it. But > personally, I don't.) JSON is a fantastic format for transmitting > complex objects around the internet; it's compact (unlike XML), > readable in many languages (like XML), easily readable by humans > (UNLIKE XML!), and can represent all the most common data structures > (subtly, XML can't technically do this). It's superb at what it > does... but it doesn't do Python GUIs. For those, use Python itself. > I find that I am using JSON and XML more and more in my project, so I thought I would explain what I am doing to see if others think this is an acceptable approach or if I have taken a wrong turn. I have various data structures, some simple, some more complex, of which I have many instances. I want to serialise and store them in a database. This has two benefits. Firstly, I just have to write one piece of python code that interprets and deals with each structure, so it avoids duplicate code. Secondly, I can design a gui that exposes the structures to non-programmers, giving them the ability to modify them or create new ones. Simple structures can be expressed in JSON. I use XML to represent the more complex ones. I will give two examples, one simple and one complex. I store database metadata in the database itself. I have a table that defines each table in the database, and I have a table that defines each column. Column definitions include information such as data type, allow null, allow amend, maximum length, etc. Some columns require that the value is constrained to a subset of allowable values (e.g. 'title' must be one of 'Mr', 'Mrs', etc.). I know that this can be handled by a 'check' constraint, but I have added some additional features which can't be handled by that. So I have a column in my column-definition table called 'choices', which contains a JSON'd list of allowable choices. It is actually more complex than that, but this will suffice for a simple example. For my more complex example, I should explain that my project involves writing a generalised business/accounting system. Anyone who has worked on these knows that you quickly end up with hundreds of database tables storing business data, and hundreds of forms allowing users to CRUD the data (create/read/update/delete). Each form is unique, and yet they all share a lot of common characteristics. I have abstracted the contents of a form sufficiently that I can represent at least 90% of it in XML. This is not just the gui, but all the other elements - the tables required, any input parameters, any output parameters, creating any variables to be used while entering the form, any business logic to be applied at each point, etc. Each form definition is stored as gzip'd XML in a database, and linked to the menu system. There is just one python program that responds to the selection of a menu option, retrieves the form from the database, unpacks it and runs it. Incidentally, I would take issue with the comment that 'JSON is easily readable by humans (UNLIKE XML)'. Here is a more complete example of my 'choices' definition. [true, true, [["admin", "System administrator", [], []], ["ind", "Individual", [["first_name", true], ["surname", true]], [["first_name", " "], ["surname", ""]]], ["comp", "Company", [["comp_name", true], ["reg_no", true], ["vat_no", false]], [["comp_name", ""] You can read it, but what does it mean? This is what it would look like if I stored it in XML - More verbose - sure. Less human-readable - I don't think so. Also, intuitively one would think it would take much longer to process the XML version compared with the JSON version. I have not done any benchmarks, but I u
Re: The potential for a Python 2.8.
Le vendredi 24 janvier 2014 01:42:41 UTC+1, Terry Reedy a écrit : > > > > This will never happen. Python 3 is the escape from several dead-ends in > > Python 2. The biggest in impact is the use of un-accented latin chars as > > text in a global, unicode world. > > > Three days of discussion on how to make the next release more "ascii" compatible. I put "ascii" in quotes, because the efforts to define "ascii" were more laughable. jmf -- https://mail.python.org/mailman/listinfo/python-list
Single Object Detection and Tracking Steps
I am doing single object detection and tracking in a video file using python & opencv2. As far I know the steps are, Video to frame conversion Grayscale conversion Thresholding After phase 3, I got sequence of binary images. My questions are: How to identify (detect) whether the object is moving or not? How to get(track) the object moving coordinates(x,y position)? Which method should I use for these? I got confused with the words like SIFT feature, Kalman filter, Particle filter, optical flow filter etc. Please help me by giving next upcoming steps details. Thanks in advance. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
On Friday, January 24, 2014 2:51:12 PM UTC+5:30, Frank Millman wrote: > Incidentally, I would take issue with the comment that 'JSON is easily > readable by humans (UNLIKE XML)'. Here is a more complete example of my > 'choices' definition. > [true, true, [["admin", "System administrator", [], []], ["ind", > "Individual", [["first_name", true], ["surname", true]], [["first_name", " > "], ["surname", ""]]], ["comp", "Company", [["comp_name", true], ["reg_no", > true], ["vat_no", false]], [["comp_name", ""] > You can read it, but what does it mean? > This is what it would look like if I stored it in XML - > More verbose - sure. Less human-readable - I don't think so. > Also, intuitively one would think it would take much longer to process the > XML version compared with the JSON version. I have not done any benchmarks, > but I use lxml, and I am astonished at the speed. Admittedly a typical > form-processor spends most of its time waiting for user input. Even so, for > my purposes, I have never felt the slightest slowdown caused by XML. > Comments welcome. Of json/XML/yml I prefer yml because it has the terseness of json and the structuredness of xml -- well almost The flipside is that pyyaml needs to be installed unlike json. But then you are installing lxml anyway -- https://mail.python.org/mailman/listinfo/python-list
Need Help with Programming Science Project
I have a science project that involves designing a program which can examine a bit of text with the author's name given, then figure out who the author is if another piece of example text without the name is given. I so far have three different authors in the program and have already put in the example text but for some reason, the program always leans toward one specific author, Suzanne Collins, no matter what insane number I try to put in or how much I tinker with the coding. I would post the code, but I don't know if it's fine to put it here, as it contains pieces from books. I do believe that would go against copyright laws. If I can figure out a way to put it in without the bits from the stories, then I'll do so, but as of now, any help is appreciated. I understand I'm not exactly making it easy since I'm not putting up any code, but I'm kind of desperate for help here, as I can't seem to find anybody or anything else helpful in any way. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help with Programming Science Project
theguy wrote:
> I have a science project that involves designing a program which can
> examine a bit of text with the author's name given, then figure out who
> the author is if another piece of example text without the name is given.
> I so far have three different authors in the program and have already put
> in the example text but for some reason, the program always leans toward
> one specific author, Suzanne Collins, no matter what insane number I try
> to put in or how much I tinker with the coding. I would post the code, but
> I don't know if it's fine to put it here, as it contains pieces from
> books. I do believe that would go against copyright laws. If I can figure
> out a way to put it in without the bits from the stories, then I'll do so,
> but as of now, any help is appreciated. I understand I'm not exactly mak
> ing it easy since I'm not putting up any code, but I'm kind of desperate
> for help here, as I can't seem to find anybody or anything else helpful
> in any way. Thank you.
If I were to speculate what your program might look like:
text_samples = {
"Suzanne Collins": "... some text by collins ...",
"J. K. Rowling": "... some text by rowling ...",
#...
}
unknown = "... sample text by unknown author ..."
def calc_match(text1, text2):
import random
return random.random()
guessed_author = None
guessed_match = None
for author, text in text_samples.items():
match = calc_match(unknown, text)
print(author, match)
if guessed_author is None or match > guessed_match:
guessed_author = author
guessed_match = match
print("The author is", guessed_author)
The important part in this script are not the text samples or the loop to
determine the best match -- it's the algorithm used to determine how good
two texts match.
In the above example that algorithm is encapsulated in the calc_match()
function and it's really bad, it gives you random numbers between 0 and 1.
For us to help you it should be sufficient when you post the analog of this
function in your code together with a description in plain english of how it
is meant to calculate the similarity between two texts.
Alternatavely, instead of the copyrighted texts grab text samples from
project gutenberg with expired copyright.
Make sure that the resulting post is as short as possible -- long text
samples don't make the post clearer than short ones.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
On Fri, Jan 24, 2014 at 8:21 PM, Frank Millman wrote:
> I find that I am using JSON and XML more and more in my project, so I
> thought I would explain what I am doing to see if others think this is an
> acceptable approach or if I have taken a wrong turn.
Please don't take this the wrong way, but the uses of JSON and XML
that you describe are still completely inappropriate. Python does not
need this sort of thing.
> I store database metadata in the database itself. I have a table that
> defines each table in the database, and I have a table that defines each
> column. Column definitions include information such as data type, allow
> null, allow amend, maximum length, etc. Some columns require that the value
> is constrained to a subset of allowable values (e.g. 'title' must be one of
> 'Mr', 'Mrs', etc.). I know that this can be handled by a 'check' constraint,
> but I have added some additional features which can't be handled by that. So
> I have a column in my column-definition table called 'choices', which
> contains a JSON'd list of allowable choices. It is actually more complex
> than that, but this will suffice for a simple example.
This is MySQL-style of thinking, that a database is a thing that's
interpreted by an application. The better way to do it is to craft a
check constraint; I don't know what features you're trying to use that
can't be handled by that, but (at least in PostgreSQL) I've never had
anything that can't be expressed that way. With the simple example you
give, incidentally, it might be better to use an enumeration rather
than a CHECK constraint, but whichever way.
> For my more complex example, I should explain that my project involves
> writing a generalised business/accounting system. Anyone who has worked on
> these knows that you quickly end up with hundreds of database tables storing
> business data, and hundreds of forms allowing users to CRUD the data
> (create/read/update/delete). Each form is unique, and yet they all share a
> lot of common characteristics. I have abstracted the contents of a form
> sufficiently that I can represent at least 90% of it in XML. This is not
> just the gui, but all the other elements - the tables required, any input
> parameters, any output parameters, creating any variables to be used while
> entering the form, any business logic to be applied at each point, etc. Each
> form definition is stored as gzip'd XML in a database, and linked to the
> menu system. There is just one python program that responds to the selection
> of a menu option, retrieves the form from the database, unpacks it and runs
> it.
Write your rendering engine as a few simple helper functions, and then
put all the rest in as code instead of XML. The easiest way to go
about it is to write three forms, from scratch, and then look at the
common parts and figure out which bits can go into helper functions.
You'll find that you can craft a powerful system with just a little
bit of code, if you build it right, and it'll mean _less_ library code
than you currently have as XML. If you currently represent 90% of it
in XML, then you could represent 90% of it with simple calls to helper
functions, which is every bit as readable (probably more so), and much
*much* easier to tweak. Does your XML parsing engine let you embed
arbitrary expressions into your code? Can you put a calculated value
somewhere? With Python, everything's code, so there's no difference
between saying "foo(3)" and saying "foo(1+2)".
> Incidentally, I would take issue with the comment that 'JSON is easily
> readable by humans (UNLIKE XML)'. Here is a more complete example of my
> 'choices' definition.
>
> [true, true, [["admin", "System administrator", [], []], ["ind",
> "Individual", [["first_name", true], ["surname", true]], [["first_name", "
> "], ["surname", ""]]], ["comp", "Company", [["comp_name", true], ["reg_no",
> true], ["vat_no", false]], [["comp_name", ""]
>
> You can read it, but what does it mean?
>
> This is what it would look like if I stored it in XML -
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> More verbose - sure. Less human-readable - I don't think so.
Well, that's because you elided all the names in the JSON version. Of
course that's not a fair comparison. :) Here's how I'd render that XML
in JSON. I assume that this is stored in a variable, database field,
or whatever, named "choices", and so I skip that first-level name.
{"use_subtypes":true, "use_displaynames":true, "choice":[
{"code":"admin", "descr":"System administrator",
"subtype_columns":[], "displaynames":[]},
{"code":"ind", "descr":"Individual",
"subtype_columns":[
{"col_name":"first_name", "required":true},
{"col_name":"surname", "required":true}
], "displaynames":[
{"col_name":"first_name", "separator":" "},
{
Re: Python declarative
On Wednesday, January 15, 2014 7:02:08 PM UTC+2, Sergio Tortosa Benedito wrote:
> Hi I'm developing a sort of language extension for writing GUI programs
> called guilang, right now it's written in Lua but I'm considreing Python
> instead (because it's more tailored to alone applications). My question
> it's if I can achieve this declarative-thing in python. Here's an
> example:
> Window "myWindow" {
> title="Hello world";
> Button "myButton" {
> label="I'm a button";
> onClick=exit
> }
> }
> print(myWindow.myButton.label)
> Of course it doesn't need to be 100% equal. Thanks in advance
> Sergio
you can also encode widget event handler
function names into same text file and module names where
functions are written so they will be called by string name.
The only thing will be left - creation of those module(s).py
and writing functions there and of course the subject of your
project interpreter/mapper/creator of encoded text to graphical
primitives.
For convenience text encoding can retain properties of
widget library you will choose. or you can/should
also create derived widgets with some predefined look and feel
and properties to make encoding simpler and typing faster.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
"Chris Angelico" wrote in message news:captjjmo+euy439wb0c8or+zacyenr844hakwl3i2+55dde8...@mail.gmail.com... > On Fri, Jan 24, 2014 at 8:21 PM, Frank Millman wrote: >> I find that I am using JSON and XML more and more in my project, so I >> thought I would explain what I am doing to see if others think this is an >> acceptable approach or if I have taken a wrong turn. > > Please don't take this the wrong way, but the uses of JSON and XML > that you describe are still completely inappropriate. Python does not > need this sort of thing. > Chris, I really am very grateful for your detailed response. There is much food for thought there and I will have to read it a few times to glean as much as possible from it. Here are some initial thoughts. 1. I don't really understand how your system actually works! You mention Python code and helper functions, but I cannot picture the overall structure of the program. I don't know if it is possible to provide a siimple example, but it would certainly help. 2. I am not sure if you have created this to make it easy for *you* to create forms, or for others. And if the latter, must they be programmers? One of my goals is to allow non-programmers to modify forms and even create them from scratch. I did mention that one benefit of my approach is that I can design a gui that allows this, but I don't get the sense that your's does. 3. Thanks for the links to the Inner Platform Effect. I had not heard of it, but I recognise the symptoms, and I realise that I am skirting close to it in some areas. 4. You are right that some things cannot be totally abstracted, and can only be handled by code. My approach is as follows. If at least 80% of the structure can be handled without resorting to code, I think it is worthwhile, and I think I have more than achieved that. Of the balance, if at least 80% of requirements are 'standard', I can write the standard functions in Python, and create an XML tag that will cause the function to be invoked at run-time. The 'designer' still does not have to worry about Python. For the remainder, I have created an XML tag called 'pyfunc' that provides a path to a custom-written function. For this, a Python programmer will be required. So far I have only made use of this in my 'form designer', which is quite complex as it has to take the XML definition and 'explode' it into a number of in-memory tables so that it can be presented in gui form. However, the average user is not going to get their hands that dirty. Thanks again Frank -- https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
"Rustom Mody" wrote in message news:[email protected]... > On Friday, January 24, 2014 2:51:12 PM UTC+5:30, Frank Millman wrote: > Comments welcome. > > Of json/XML/yml I prefer yml because it has the terseness of json and the > structuredness of xml -- well almost > > The flipside is that pyyaml needs to be installed unlike json. > But then you are installing lxml anyway Thanks for that, Rustom. I had a quick look and I like it. Probably too big a change for me to consider at the moment, but at least I am now aware of it. Frank -- https://mail.python.org/mailman/listinfo/python-list
Re: generate De Bruijn sequence memory and string vs lists
On Fri, Jan 24, 2014 at 2:29 AM, Gregory Ewing wrote: > If all you want is a mapping between a sequence of > length n and compact representation of it, there's > a much simpler way: just convert it to a base-k > integer, where k is the size of the alphabet. > > The resulting integer won't be any larger than an > index into the de Bruijn sequence would be, and > you can easily recover the original sequence from > its encoding without needing any kind of lookup > table. > True, the "all you want is a mapping" is not quite true. I actually plan to plot frequency (the number of times an observed sub sequence overlaps a value in the De Bruijn sequence) The way the sub sequences overlap is important to me and I don't see a way go from base-k (or any other base) to the index location in the De Bruijn sequence. i.e. a decoding algorithm. Vincent Davis 720-301-3003 -- https://mail.python.org/mailman/listinfo/python-list
Re: generate De Bruijn sequence memory and string vs lists
On Fri, Jan 24, 2014 at 2:23 AM, Peter Otten <[email protected]> wrote: > Then, how do you think Python /knows/ that it has to repeat the code 10 > times on my "slow" and 100 times on your "fast" machine? It runs the bench > once, then 10, then 100, then 1000 times -- until there's a run that takes > 0.2 secs or more. The total expected minimum time without startup overhead > is then > Ah, I did not know about the calibration. That and I did not notice the 100 on my machine vs 10 on yours. Vincent Davis -- https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
On 01/24/14 11:21, Frank Millman wrote:
> I store database metadata in the database itself. I have a table that
> defines each table in the database, and I have a table that defines each
> column. Column definitions include information such as data type, allow
> null, allow amend, maximum length, etc. Some columns require that the value
> is constrained to a subset of allowable values (e.g. 'title' must be one of
> 'Mr', 'Mrs', etc.). I know that this can be handled by a 'check' constraint,
> but I have added some additional features which can't be handled by that. So
> I have a column in my column-definition table called 'choices', which
> contains a JSON'd list of allowable choices. It is actually more complex
> than that, but this will suffice for a simple example.
I wonder whether your use cases can be fully handled by Xml Schema
standard. It's quite robust and easy to use. You are already doing
validation at the app level so I don't think it'd be much of a problem
for you to adopt it.
e.g.
>>> from spyne.model import *
>>> class C(ComplexModel):
... title = Unicode(values=['Mr', 'Mrs', 'Ms'])
...
>>> from lxml import etree
>>> from spyne.util.xml import get_validation_schema
>>> schema = get_validation_schema([C], 'some_ns')
>>> doc1 = etree.fromstring('Mr')
>>> print schema.validate(doc1)
True
>>> doc2 = etree.fromstring('xyz')
>>> print schema.validate(doc2)
False
>>> print schema.error_log
:1:0:ERROR:SCHEMASV:SCHEMAV_CVC_ENUMERATION_VALID: Element
'{some_ns}title': [facet 'enumeration'] The value 'xyz' is not an
element of the set {'Mr', 'Mrs', 'Ms'}.
:1:0:ERROR:SCHEMASV:SCHEMAV_CVC_DATATYPE_VALID_1_2_1: Element
'{some_ns}title': 'xyz' is not a valid value of the atomic type
'{some_ns}C_titleType'.
>>>
Also, if you need conversion between various serialization formats and
Python object hierarchies, I put together an example for you:
https://gist.github.com/plq/8596519
I hope these help.
Best,
Burak
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
On Fri, Jan 24, 2014 at 11:49 PM, Frank Millman wrote:
>
> "Chris Angelico" wrote in message
> news:captjjmo+euy439wb0c8or+zacyenr844hakwl3i2+55dde8...@mail.gmail.com...
>> On Fri, Jan 24, 2014 at 8:21 PM, Frank Millman wrote:
>>> I find that I am using JSON and XML more and more in my project, so I
>>> thought I would explain what I am doing to see if others think this is an
>>> acceptable approach or if I have taken a wrong turn.
>>
>> Please don't take this the wrong way, but the uses of JSON and XML
>> that you describe are still completely inappropriate. Python does not
>> need this sort of thing.
>>
>
> Chris, I really am very grateful for your detailed response. There is much
> food for thought there and I will have to read it a few times to glean as
> much as possible from it.
Thanks for taking it the right way :) If I thought you were doing a
terrible job, I'd just archive the thread and move on. The detailed
response means I think you're very close to the mark, but could
improve. :)
> Here are some initial thoughts.
>
> 1. I don't really understand how your system actually works! You mention
> Python code and helper functions, but I cannot picture the overall structure
> of the program. I don't know if it is possible to provide a siimple example,
> but it would certainly help.
Yeah, it was a bit vague. Unfortunately I haven't actually built any
complex UI in Python, ever, so I'll have to use C, C++, REXX, or Pike,
for the example. In C, it would be using the OS/2 APIs, not very
useful to anyone else. In C++, either Borland's ancient "Object
Windows Library", or the Win32 APIs - either way, not particularly
helpful. REXX you probably don't even know as a language, and you're
unlikely to know any of the GUI libraries I've used - GpfRexx, VREXX,
VX-REXX, VisPro REXX, DrRexx, or a handful of others. So the best bet
is Pike, where I've used GTK, which is also available for Python - but
there are distinct differences. (Oh, I've also used DBExpert, which is
a superb example of how frustrating it can be to try to create a
complex GUI in a "look how easy, it's just drag and drop, no code
needed" system. But that's more arcane stuff from the 1990s that you
most likely don't know, and definitely don't need to know.)
So, here's some code from Gypsum. Firstly, here's a simple window
layout (not strictly what I had in Gypsum):
mainwindow = GTK2.Window(0)->add(GTK2.Vbox(0,0)
->add(GTK2.Label("About Gypsum: big long multi-line string"))
->add(GTK2.HbuttonBox()
->add(GTK2.Button("Close"))
->add(GTK2.Button("Foobar"))
)
);
The window has a simple structure. It contains a vertical box, which
contains a label and a horizontal button box; the latter contains two
buttons. (The real about dialog has only one button, making it a poor
example. I've no idea what clicking Foobar on an about dialog should
do.)
There's a nested structure to it, and it's all code. (It's actually
all one single expression. The add() methods return the parent object,
so they chain nicely.) This gives maximum flexibility, but it gets
repetitive at times, especially when I do up the character sheet.
Here's a screenshot of just the first page:
http://rosuav.com/charsheet.png
(That's how it appears on Windows, since I'm currently testing it for
support there. It also has to work - and look right - on Linux and Mac
OS.)
It's particularly complicated when laying out a table, because the
table is so powerful and flexible.
GTK2.Table(6,2,0)
->attach(GTK2.Label((["label":"Keyword","xalign":1.0])),0,1,0,1,GTK2.Fill,GTK2.Fill,5,0)
->attach_defaults(win->kwd=GTK2.Entry(),1,2,0,1)
->attach(GTK2.Label((["label":"Name","xalign":1.0])),0,1,1,2,GTK2.Fill,GTK2.Fill,5,0)
->attach_defaults(win->name=GTK2.Entry(),1,2,1,2)
->attach(GTK2.Label((["label":"Host
name","xalign":1.0])),0,1,2,3,GTK2.Fill,GTK2.Fill,5,0)
->attach_defaults(win->hostname=GTK2.Entry(),1,2,2,3)
->attach(GTK2.Label((["label":"Port","xalign":1.0])),0,1,3,4,GTK2.Fill,GTK2.Fill,5,0)
->attach_defaults(win->port=GTK2.Entry(),1,2,3,4)
->attach(GTK2.Label((["label":"Auto-log","xalign":1.0])),0,1,4,5,GTK2.Fill,GTK2.Fill,5,0)
->attach_defaults(win->logfile=GTK2.Entry(),1,2,4,5)
->attach(win->use_ka=GTK2.CheckButton("Use
keep-alive"),1,2,5,6,GTK2.Fill,GTK2.Fill,5,0) //No separate label
Horribly repetitive, and requires care to ensure that the
left/right/top/bottom boundaries are correct in all cases. Technically
it's possible for widgets to span rows or columns, and even to
overlap, but that's extremely rare compared to the common case of just
"lay these things out in a grid". (Though spanning columns was easy
enough to implement, so I did it.)
Here's the version with the first helper function:
GTK2Table(({
({"Keyword",win->kwd=GTK2.Entry
Re: Elementree and insert new element if it is not present - FIXED
On 2014-01-24, Tharanga Abeyseela wrote: > manged to fix it. need to add the namespace when checking the > condition. I wish there was a rule that if your xml doesn't need a namespace it doesn't use one. They are a pain when there's just one useless namespace. But maybe I'm just naive. -- Neil Cerutti -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
indar kumar writes: > On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: >> Hi, >> >> >> >> I want to show a code for review but afraid of plagiarism issues. >> Kindly, suggest how can I post it for review here without masking it >> visible for public > > Can I do the following to just get the value as string not the type list? > > searchfor = '192.168.0.2' > z=[ii[0] for ii in hosts.values() if ii[1] == searchfor] str1 = ''.join(z) str1 If you want to extract an element of a list use indexing, like mylist[0]. If you don't know these things or can't find this out yourself, you have a serious lack of knowledge about Python, or maybe about programming, and it is time to learn that first. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] -- https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
On 24/01/2014 09:33, [email protected] wrote: [double spacing snipped for the 10**infinity time] Le vendredi 24 janvier 2014 01:42:41 UTC+1, Terry Reedy a écrit : This will never happen. Python 3 is the escape from several dead-ends in Python 2. The biggest in impact is the use of un-accented latin chars as text in a global, unicode world. Three days of discussion on how to make the next release more "ascii" compatible. I put "ascii" in quotes, because the efforts to define "ascii" were more laughable. jmf Oh dear of dear, looks as if another bad batch has been sold, please change your dealer immediately. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
On 2014-01-24, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith wrote: >> >> Python 2.8j? >> > >> > You're imagining things. >> >> Get real... s'not gonna happen. >> > I wouldn't bet on that. The situation keeps getting tensor and > tensor. I have a feeling there's a pun there based on the worlds "real" and "tensor", but I don't have the math skills required to figure it out. -- Grant Edwards grant.b.edwardsYow! If I pull this SWITCH at I'll be RITA HAYWORTH!! gmail.comOr a SCIENTOLOGIST! -- https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
On Sat, Jan 25, 2014 at 2:36 AM, Grant Edwards wrote: > On 2014-01-24, Roy Smith wrote: >> In article , >> Chris Angelico wrote: >> >>> On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith wrote: >>> >> Python 2.8j? >>> > >>> > You're imagining things. >>> >>> Get real... s'not gonna happen. >>> >> I wouldn't bet on that. The situation keeps getting tensor and >> tensor. > > I have a feeling there's a pun there based on the worlds "real" and > "tensor", but I don't have the math skills required to figure it out. MRAB suggested "2.8j", which looks like another system of version number (where you go 2.8, then 2.8a, 2.8b, etc etc), but is a pun on the notation for imaginary/complex numbers. Hence Roy said "imagining" things. I tried to call him back to "real" numbers (ones that don't involve the letter j), and Roy remarked in a way that mentioned tensors [1], which can represent complex numbers, but I've never dug into all that myself, so I'll let him explain in more detail. I then said (though you didn't quote me) that this was a "rational" discussion until I suggested a version number involving e, which is an irrational number (2.71828...), as is sqrt(8) which I also mentioned at the same time (2.8284...). I just violated [2]. Sorry. ChrisA [1] http://en.wikipedia.org/wiki/Tensor [2] http://tvtropes.org/pmwiki/pmwiki.php/Main/DontExplainTheJoke -- https://mail.python.org/mailman/listinfo/python-list
Re: datetime as subclass of date
One thing that always reinforced my notion that issubclass(datetime.datetime, datetime.date) should be False is that the presence of of date and time methods gives me a mental image of delegation, not inheritance. That is, it "feels" like a datetime object is the aggregation of a date object and a time object, not a specialized date object with some added time machinery mixed in. Skip -- https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 2014-01-24, 11:18 GMT, you wrote: > Write your rendering engine as a few simple helper functions, > and then put all the rest in as code instead of XML. The > easiest way to go about it is to write three forms, from > scratch, and then look at the common parts and figure out > which bits can go into helper functions. Perhaps what's missing is full acknowledgment that Python has dual-inheritance and thus it can have mixin classes (which seems to me to be the only useful use of dual inheritance). You know you can have mixins in Python, right? Also, I wrote my share of XML parsing/writing code, but more and more I am persuaded that if the answer is “XML” then there is some wrong with the question. Python is a way more expressive language than XML, so it is almost always more useful to write in Python, than to pass any problems to XML. Matěj -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.22 (GNU/Linux) iD8DBQFS4pS54J/vJdlkhKwRApdcAJ48PRgDz6ccnq1YFD9zx8EDDH3JjgCghU2x 3CV+D0LvquzgYRux2GslZ0E= =Y3/F -END PGP SIGNATURE- -- https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
On Sat, Jan 25, 2014 at 3:28 AM, Matěj Cepl wrote: > On 2014-01-24, 11:18 GMT, you wrote: >> Write your rendering engine as a few simple helper functions, >> and then put all the rest in as code instead of XML. The >> easiest way to go about it is to write three forms, from >> scratch, and then look at the common parts and figure out >> which bits can go into helper functions. > > Perhaps what's missing is full acknowledgment that Python has > dual-inheritance and thus it can have mixin classes (which seems > to me to be the only useful use of dual inheritance). You know > you can have mixins in Python, right? Hmm, I've never really felt the need to work that way. Usually it's functions I want, not classes; but if they're classes, then generally they're just to add a couple of methods, or change the construction args, so single inheritance is plenty. (I created a MultiLineEntryField class as a thin wrapper around TextView, adding get_text() and set_text() with the same signatures as GTK2.Entry()'s methods of the same names. That wouldn't apply to anything else, so a mixin wouldn't help much.) But sure. If you want mixins, go for it. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Class and instance related questions.
Hi Is there way to get list of instances of particular class through class itself? via metaclass or any other method? Another question - if class is object is it possible to delete it? If it is possible then how instances of that class will behave? Thanks Asaf -- https://mail.python.org/mailman/listinfo/python-list
Re: Class and instance related questions.
On Sat, Jan 25, 2014 at 3:31 AM, Asaf Las wrote: > Hi > > Is there way to get list of instances of particular > class through class itself? via metaclass or any other method? Not automatically, but you can make a class that keeps track of its instances with a weak reference system. > Another question - if class is object is it possible > to delete it? If it is possible then how instances > of that class will behave? It's possible to unbind the name, but every instance retains a reference to its class, so the class itself won't disappear until there are no instances left of it. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
On 1/24/2014 10:57 AM, Chris Angelico wrote: On Sat, Jan 25, 2014 at 2:36 AM, Grant Edwards wrote: On 2014-01-24, Roy Smith wrote: In article , Chris Angelico wrote: On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith wrote: Python 2.8j? You're imagining things. Get real... s'not gonna happen. I wouldn't bet on that. The situation keeps getting tensor and tensor. I have a feeling there's a pun there based on the worlds "real" and "tensor", but I don't have the math skills required to figure it out. MRAB suggested "2.8j", which looks like another system of version number (where you go 2.8, then 2.8a, 2.8b, etc etc), but is a pun on the notation for imaginary/complex numbers. Hence Roy said "imagining" things. I tried to call him back to "real" numbers (ones that don't involve the letter j), and Roy remarked in a way that mentioned tensors [1], which can represent complex numbers, but I've never dug into all that myself, so I'll let him explain in more detail. I then said (though you didn't quote me) that this was a "rational" discussion until I suggested a version number involving e, which is an irrational number (2.71828...), as is sqrt(8) which I also mentioned at the same time (2.8284...). I just violated [2]. Sorry. ChrisA [1] http://en.wikipedia.org/wiki/Tensor [2] http://tvtropes.org/pmwiki/pmwiki.php/Main/DontExplainTheJoke In this case, the explanation is as funny as the joke. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
On Sat, Jan 25, 2014 at 4:17 AM, Terry Reedy wrote: > In this case, the explanation is as funny as the joke. I have to agree. But hey, it passes the time... ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
Hi again , I'm sorry I dind't reply earlier I still hav enot added myself to the list (I'm doing this trhough google groups). Thanks Asaf, but I don't like having the code and the GUI separated. First,I'm not aiming to not programmers (or people qho don't want to be one) because they may be able to write the layout but not the actual program's function so there's no reason to do that. Second, I wouldn't like to have code and GUI separated since it's a hassle when try to change something like the name. XML and JSON are pretty cool but they serve for loading info which can vary to a fixed engine not for when that info does not change, and that's even more true when you are speaking about an interpreted language. I've been reasearching a bit myself and this is what I got: a way of having a nice syntax in python itself (no external files, no new language...) with metaclasses, so the same example which was used in Lua (and I think in original's python syntax) would look like this with metaclasses and classes: class myWindow(Window): title="Hello World" class myButton(Button): label="Hello World" It's just like what I was looking for, with the added benefit that functions can be defined right there. It has it's own problems (like having to access variables from the global scope), but I think they are either solvable or minor. Sergio -- https://mail.python.org/mailman/listinfo/python-list
Re: Class and instance related questions.
Hi Chris Thanks for answers On Friday, January 24, 2014 6:37:29 PM UTC+2, Chris Angelico wrote: > On Sat, Jan 25, 2014 at 3:31 AM, Asaf Las wrote: > > Hi > > Is there way to get list of instances of particular > > class through class itself? via metaclass or any other method? > Not automatically, but you can make a class that keeps track of its > instances with a weak reference system. By "not automatically" do you mean there is no way to get references to instances of class via python's provided methods or attributes for class object at time the class object is created? And usage of weak reference was suggested only to allow class instances garbage collected if for example class static container attribute will be used as class instance reference storage? > > Another question - if class is object is it possible > > to delete it? If it is possible then how instances > > of that class will behave? > > It's possible to unbind the name, but every instance retains a > reference to its class, so the class itself won't disappear until > there are no instances left of it. > > ChrisA That is interesting. Is it also reference count mechanism or something else? Thanks Asaf -- https://mail.python.org/mailman/listinfo/python-list
Re: Class and instance related questions.
On Sat, Jan 25, 2014 at 7:32 AM, Asaf Las wrote: > On Friday, January 24, 2014 6:37:29 PM UTC+2, Chris Angelico wrote: >> On Sat, Jan 25, 2014 at 3:31 AM, Asaf Las wrote: >> > Hi >> > Is there way to get list of instances of particular >> > class through class itself? via metaclass or any other method? >> Not automatically, but you can make a class that keeps track of its >> instances with a weak reference system. > > By "not automatically" do you mean there is no way to get references to > instances of class via python's provided methods or attributes for class > object at time the class object is created? Correct. > And usage of weak reference was suggested only to allow class instances > garbage collected if for example class static container attribute will be > used as class instance reference storage? Weak references mean that the objects will be disposed of as normal, but that you'll know that they've gone. >> > Another question - if class is object is it possible >> > to delete it? If it is possible then how instances >> > of that class will behave? >> >> It's possible to unbind the name, but every instance retains a >> reference to its class, so the class itself won't disappear until >> there are no instances left of it. >> >> ChrisA > > That is interesting. Is it also reference count mechanism or something else? Yes. [1] ChrisA [1] Within the bounds of the question asked, I think a simple "Yes" is more useful here than a long and detailed explanation of the many Pythons and how not all of them refcount at all. Consider this footnote my apology to the experts who would otherwise feel that I'm majorly misleading the OP. Sorry. -- https://mail.python.org/mailman/listinfo/python-list
Re: Single Object Detection and Tracking Steps
On 2014-01-24, [email protected] wrote: > I am doing single object detection and tracking in a video file using > python & opencv2. As far I know the steps are, > > Video to frame conversion > Grayscale conversion > Thresholding > After phase 3, I got sequence of binary images. > > My questions are: > > How to identify (detect) whether the object is moving or not? > How to get(track) the object moving coordinates(x,y position)? > Which method should I use for these? > I got confused with the words like SIFT feature, Kalman filter, Particle > filter, optical flow filter etc. Please help me by giving next upcoming > steps details. > > Thanks in advance. I assume this is homework, so better ask other students. -- Improve at backgammon rapidly through addictive quickfire position quizzes: http://www.bgtrain.com/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Class and instance related questions.
On Friday, January 24, 2014 10:45:30 PM UTC+2, Chris Angelico wrote: > On Sat, Jan 25, 2014 at 7:32 AM, Asaf Las wrote: > > On Friday, January 24, 2014 6:37:29 PM UTC+2, Chris Angelico wrote: > >> On Sat, Jan 25, 2014 at 3:31 AM, Asaf Las wrote: > >> > Hi > >> > Is there way to get list of instances of particular > >> > class through class itself? via metaclass or any other method? > >> Not automatically, but you can make a class that keeps track of its > >> instances with a weak reference system. > > By "not automatically" do you mean there is no way to get references > > to instances of class via python's provided methods or attributes for class > > object at time the class object is created? > > Correct. > > > And usage of weak reference was suggested only to allow class instances > > garbage collected if for example class static container attribute will be > > used as class instance reference storage? > Weak references mean that the objects will be disposed of as normal, > but that you'll know that they've gone. > > >> > Another question - if class is object is it possible > >> > to delete it? If it is possible then how instances > >> > of that class will behave? > > >> It's possible to unbind the name, but every instance retains a > >> reference to its class, so the class itself won't disappear until > >> there are no instances left of it. > >> ChrisA > > > That is interesting. Is it also reference count mechanism or something else? > > Yes. [1] > > ChrisA > > [1] Within the bounds of the question asked, I think a simple "Yes" is > more useful here than a long and detailed explanation of the many > Pythons and how not all of them refcount at all. Consider this > footnote my apology to the experts who would otherwise feel that I'm > majorly misleading the OP. Sorry. Chris, i like answers which open doors to my curiosity :-) yet i should spend my credits very carefully :-) Thanks Asaf -- https://mail.python.org/mailman/listinfo/python-list
Re: Class and instance related questions.
On Sat, Jan 25, 2014 at 8:03 AM, Asaf Las wrote: > Chris, i like answers which open doors to my curiosity :-) > yet i should spend my credits very carefully :-) Trust me, there is no limit to what you can learn when you have that kind of curiosity! Ask more questions and you'll get more details. Around here, we have all sorts of experts (several core Python developers hang out here, at least one of whom posts fairly frequently), and a good number of us have a decade or two of experience in programming, having used a large number of languages, and we've all settled on Python as being in some way important to us. It's always interesting to get a discussion going with people whose non-Python expertise differs - a couple of us (self included) here are very familiar with REXX, some know Ruby (self NOT included), or lisp, or go, or anything else under the sun. And then there are those of us who'll quote Alice in Wonderland, or the Thomas the Tank Engine books, or abstract philosophy, or Gilbert and Sullivan, or Discworld (I think I've seen that one quoted? I'm not personally familiar, so I can't say for sure), or Firefly, or Real Genius, or ... or , you get the idea :) So you get to learn about all sorts of other nerdy interests for free! ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Class and instance related questions.
On Friday, January 24, 2014 11:18:08 PM UTC+2, Chris Angelico wrote: > On Sat, Jan 25, 2014 at 8:03 AM, Asaf Las wrote: > > Chris, i like answers which open doors to my curiosity :-) > > yet i should spend my credits very carefully :-) > Trust me, there is no limit to what you can learn when you have that > kind of curiosity! Ask more questions and you'll get more details. > Around here, we have all sorts of experts (several core Python > developers hang out here, at least one of whom posts fairly > frequently), and a good number of us have a decade or two of > experience in programming, having used a large number of languages, > and we've all settled on Python as being in some way important to us. > It's always interesting to get a discussion going with people whose > non-Python expertise differs - a couple of us (self included) here are > very familiar with REXX, some know Ruby (self NOT included), or lisp, > or go, or anything else under the sun. And then there are those of us > who'll quote Alice in Wonderland, or the Thomas the Tank Engine books, > or abstract philosophy, or Gilbert and Sullivan, or Discworld (I think > I've seen that one quoted? I'm not personally familiar, so I can't say > for sure), or Firefly, or Real Genius, or ... or , you get the > idea :) So you get to learn about all sorts of other nerdy interests > for free! > ChrisA I appreciate your kind words! Thanks Asaf -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
I had offered to provide some off-line tutoring. My reaction is exactly what you are saying - he needs to learn the basics. The code he sent me (after much asking to see some code) was buggy, and a lot of it were the various suggestions we all made. I feel for indar. He is in over his head. I recommend we stop trying to respond to all his requests. -- https://mail.python.org/mailman/listinfo/python-list
Re: Class and instance related questions.
Asaf Las Wrote in message: > On Friday, January 24, 2014 10:45:30 PM UTC+2, Chris Angelico wrote: >> On Sat, Jan 25, 2014 at 7:32 AM, Asaf Las wrote: >> > On Friday, January 24, 2014 6:37:29 PM UTC+2, Chris Angelico wrote: >> >> >> It's possible to unbind the name, but every instance retains a >> >> reference to its class, so the class itself won't disappear until >> >> there are no instances left of it. >> >> ChrisA >> >> > That is interesting. Is it also reference count mechanism or something >> > else? >> >> Yes. [1] >> >> ChrisA >> >> [1] Within the bounds of the question asked, I think a simple "Yes" is >> more useful here than a long and detailed explanation of the many >> Pythons and how not all of them refcount at all. Consider this >> footnote my apology to the experts who would otherwise feel that I'm >> majorly misleading the OP. Sorry. > > Chris, i like answers which open doors to my curiosity :-) > yet i should spend my credits very carefully :-) > Rather than dwelling on reference counting, which is just one mechanism for identifying and disposing of objects, it's usually more fruitful to consider what it means to be unreferenced. The usual term is "reachable. " If an object cannot be reached by following some chain of references, starting from a small list of kernel items, then it should be freed. The cheap way of noticing some such objects is by noticing the reference count go to zero. That's not enough, however, so you also need to periodically run a sweep type of garbage collector. See if you can guess why reference count alone is inadequate. The CPython system uses both of these, but other implementations do not. I believe that I've heard that the jython system does nothing at all, just letting the Java runtime handle it. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help with Programming Science Project
On 1/24/2014 5:05 AM, theguy wrote: I have a science project that involves designing a program which can examine a bit of text with the author's name given, then figure out who the author is if another piece of example text without the name is given. I so far have three different authors in the program and have already put in the example text but for some reason, the program always leans toward one specific author, Suzanne Collins, no matter what insane number I try to put in or how much I tinker with the coding. I would post the code, but I don't know if it's fine to put it here, as it contains pieces from books. I do believe that would go against copyright laws. AFAIK copyright laws apply to reproducing something for profit. I doubt that posting it here will matter. In any case do post your code; you could trim the fat out of the text if you need to, -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help with Programming Science Project
On Sat, Jan 25, 2014 at 10:38 AM, bob gailer wrote: > On 1/24/2014 5:05 AM, theguy wrote: >> >> I have a science project that involves designing a program which can >> examine a bit of text with the author's name given, then figure out who the >> author is if another piece of example text without the name is given. I so >> far have three different authors in the program and have already put in the >> example text but for some reason, the program always leans toward one >> specific author, Suzanne Collins, no matter what insane number I try to put >> in or how much I tinker with the coding. I would post the code, but I don't >> know if it's fine to put it here, as it contains pieces from books. I do >> believe that would go against copyright laws. > > AFAIK copyright laws apply to reproducing something for profit. I doubt that > posting it here will matter. Incorrect; posting not-for-profit can still be a violation of copyright. But as Peter said, the text itself isn't critical. Post with placeholder text, as he suggested, and we can look at the code. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
In article , Grant Edwards wrote: > On 2014-01-24, Roy Smith wrote: > > In article , > > Chris Angelico wrote: > > > >> On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith wrote: > >> >> Python 2.8j? > >> > > >> > You're imagining things. > >> > >> Get real... s'not gonna happen. > >> > > I wouldn't bet on that. The situation keeps getting tensor and > > tensor. > > I have a feeling there's a pun there based on the worlds "real" and > "tensor", but I don't have the math skills required to figure it out. You must be pretty weak in math, then. This really isn't that complex. [some of you who hang out on panix know where this is heading...] -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help with Programming Science Project
bob gailer writes: > On 1/24/2014 5:05 AM, theguy wrote: > > I would post the code, but I don't know if it's fine to put it here, > > as it contains pieces from books. I do believe that would go against > > copyright laws. > AFAIK copyright laws apply to reproducing something for profit. That's a common misconception that has never been true. http://www.faqs.org/faqs/law/copyright/myths/part1/> Copyright is a legal monopoly in a work, reserving a large set of actions to the copyright holders. Without license from the copyright holders, or an exemption under the law, you cannot legally perform those actions. Paying money may sometimes help one acquire a license to perform some reserved actions (though frequently the license is severely restricted, and frequently the license you need isn't available for any price). But “I'm not seeking a profit” nor “I didn't get any money for it” are never grounds for copyright exemptions under any jurisdiction I've ever heard of. -- \ “People are very open-minded about new things, as long as | `\ they're exactly like the old ones.” —Charles F. Kettering | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
On 2014-01-24 19:56, Roy Smith wrote: > In article , > Grant Edwards wrote: > > > On 2014-01-24, Roy Smith wrote: > > > In article > > > , Chris > > > Angelico wrote: > > > > > >> On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith > > >> wrote: > > >> >> Python 2.8j? > > >> > > > >> > You're imagining things. > > >> > > >> Get real... s'not gonna happen. > > >> > > > I wouldn't bet on that. The situation keeps getting tensor and > > > tensor. > > > > I have a feeling there's a pun there based on the worlds "real" > > and "tensor", but I don't have the math skills required to figure > > it out. > > You must be pretty weak in math, then. This really isn't that > complex. No need to be so irrational about things! -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: Class and instance related questions.
On 1/24/2014 3:45 PM, Chris Angelico wrote: On Sat, Jan 25, 2014 at 7:32 AM, Asaf Las wrote: On Friday, January 24, 2014 6:37:29 PM UTC+2, Chris Angelico wrote: On Sat, Jan 25, 2014 at 3:31 AM, Asaf Las wrote: Hi Is there way to get list of instances of particular class through class itself? via metaclass or any other method? Not automatically, but you can make a class that keeps track of its instances with a weak reference system. By "not automatically" do you mean there is no way to get references to instances of class via python's provided methods or attributes for class object at time the class object is created? Correct. This depends on exactly the meaning of your question. CPython has a gc module which has this method. gc.get_objects() Returns a list of all objects tracked by the collector, excluding the list returned. In a fresh 3.4.0 Idle shell, the list has about 15000 objects in about 150 classes. (A substantial fraction of the classes, at least, are Idle classes used in the user process.) Numbers and strings are not tracked. I believe instances of python-coded classes always are. So you can brute force search all tracked instances for instances of a class you code in Python, but this in not 'through [the] class itself'. If you plan ahead, it seems better to use a class attribute such as _instances = weakref.WeakSet() to contain them and add them in the __init__ method. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help with Programming Science Project
On 1/24/2014 7:34 PM, Chris Angelico wrote: On Sat, Jan 25, 2014 at 10:38 AM, bob gailer wrote: On 1/24/2014 5:05 AM, theguy wrote: I have a science project that involves designing a program which can examine a bit of text with the author's name given, then figure out who the author is if another piece of example text without the name is given. I so far have three different authors in the program and have already put in the example text but for some reason, the program always leans toward one specific author, Suzanne Collins, no matter what insane number I try to put in or how much I tinker with the coding. I would post the code, but I don't know if it's fine to put it here, as it contains pieces from books. I do believe that would go against copyright laws. AFAIK copyright laws apply to reproducing something for profit. I doubt that posting it here will matter. Incorrect; posting not-for-profit can still be a violation of copyright. But as Peter said, the text itself isn't critical. Post with placeholder text, as he suggested, and we can look at the code. In the US, short quotations are allowed for 'fair use'. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help with Programming Science Project
In article , Ben Finney wrote: > bob gailer writes: > > > On 1/24/2014 5:05 AM, theguy wrote: > > > I would post the code, but I don't know if it's fine to put it here, > > > as it contains pieces from books. I do believe that would go against > > > copyright laws. > > > AFAIK copyright laws apply to reproducing something for profit. > > That's a common misconception that has never been true. > > http://www.faqs.org/faqs/law/copyright/myths/part1/> > > Copyright is a legal monopoly in a work, reserving a large set of > actions to the copyright holders. Without license from the copyright > holders, or an exemption under the law, you cannot legally perform those > actions. [The rest of this post is based on my "I am not a lawyer" understanding of the law. Also, this is based on US copyright law; things may be different elsewhere, and I haven't the foggiest idea what law applies to an international forum such as this] On the other hand (where Ben Finney's post is the first hand), there is the Fair Use Doctrine (FUD), which grants certain exemptions. The US Copyright Office has a page (http://www.copyright.gov/fls/fl102.html) about this. As a real-life example, I believe I can safely invoke the FUD to quote the leading paragraphs from today's New York Times and New York Post articles about the same event and give their Fleish-Kincaid Reading Ease and Grade Level scores, if I was comparing the writing style of the two newspapers: -- NY Times: The crime gripped the publicâs imagination, for both its magnitude and its moxie: In the predawn hours of Dec. 11, 1978, a group of masked gunmen seized about $6 million in cash and jewels from a cargo building at Kennedy International Airport. Reading Ease Score: 56.6 Grade Level: 10.6 -- NY Post: On Dec. 11, 1978, armed mobsters stole $5 million in cash and nearly $1 million in jewels from a Lufthansa airlines vault at JFK Airport, in what would be for decades the biggest-ever heist on US soil. Reading Ease Score: 76.2 Grade Level: 7.3 -- The scores above were computed by http://www.readability-score.com/ In my opinion, this meets all of the requirements of the FUD. I'm quoting short passages, and using them to critique the writing styles of the two papers. In the OP's case, he's analyzing published works as input to a text analysis algorithm. In my personal opinion, posting samples of those texts, for the purpose of discussing how his algorithm works, would be well within the bounds of Fair Use. -- https://mail.python.org/mailman/listinfo/python-list
Re: The potential for a Python 2.8.
On 2014-01-25, Roy Smith wrote: > In article , > Grant Edwards wrote: > >> On 2014-01-24, Roy Smith wrote: >> > In article , >> > Chris Angelico wrote: >> > >> >> On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith wrote: >> >> >> Python 2.8j? >> >> > >> >> > You're imagining things. >> >> >> >> Get real... s'not gonna happen. >> >> >> > I wouldn't bet on that. The situation keeps getting tensor and >> > tensor. >> >> I have a feeling there's a pun there based on the worlds "real" and >> "tensor", but I don't have the math skills required to figure it out. > > You must be pretty weak in math, then. It was more of reading problem. I completely failed to notice the "j" and the "imagining". Now I get it. > This really isn't that complex. I refuse to become a vector for the spread of these bad puns. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help with Programming Science Project
Alright. I have the code here. Now, I just want to note that the code was not designed to work "quickly" or be very well-written. It was rushed, as I only had a few days to finish the work, and by the time I wrote the program, I hadn't worked with Python (which I never had TOO much experience with anyways) for a while. (About a year, maybe?) It was a bit foolish to take up the project, but here's the code anyways: #D.J. Machale - Pendragon #Pendragon: Book Six - The Rivers of Zadaa #Page 98 #The sample sentences for this author. I put each sentence into a seperate variable because I knew no other way to divide the sentence. I also removed spaces so they wouldn't be counted. djmachale_1 = 'WheretonowIaskedLoor' djmachale_2 = 'ToaplacewherewewillnotbedisturbedbyBatuorRokadorsheanswered' djmachale_3 = 'WelefttheroomfollowingLoorthroughthetwistingtunnelthatIhadwalkedthroughseveraltimesbeforeonvisitingtoZadaa' djmachale_4 = 'Shortlyweleftthesmallertunneltoenterthehugecavernthatonceheldanundergroundriver' djmachale_5 = 'WhenSpaderandIwerefirstheretherewasafour-storywaterfallononesideoftheimmensecavernthatfedadeepragingriver' djmachale_6 = 'Nowtherewasonlyadribbleofwaterthatfellfromarockymouthintoapathetictrickleofastreamatthebottomofthemostlydryriverbed' djmachale_7 = 'WhathappenedhereAlderasked' djmachale_8 = 'ThereisalottotellLooranswered' djmachale_9 = 'Later' djmachale_10 = 'Alderacceptedthat' djmachale_11 = 'Hewasaneasyguy' djmachale_12 = 'Loorledustotheopeningthatwasoncehiddenbehindthewaterfallbutwasnowinplainsight' djmachale_13 = 'Weclimbedafewstonestairssteppedthroughtheportalandenteredaroomthatheldthewater-controldeviceIhavedescribedtoyoubefore' djmachale_14 = 'Toremindyouguysthisthinglookedlikeoneofthosegiantpipe-organsthatyouseeinchurch' djmachale_15 = 'Butthesepipesranhorizontallydisappearingintotherockwalloneithersideoftheroom' djmachale_16 = 'Therewasaplatforminfrontofitthatheldanamazingarrayofswitchesandvalves' djmachale_17 = 'WhenIfirstcameheretherewasaRokadorengineeronthatplatformfeverishlyworkingthecontrolslikeanexpert' djmachale_18 = 'Ihadnoideawhatthedevicedidotherthanknowingithadsomethingtodowithcontrollingtheflowofwaterfromtherivers' djmachale_19 = 'Theguyhadmapsanddiagramsthathereferredtowhilehequicklymadeadjustmentsandtoggledswitches' djmachale_20 = 'Nowtheplatformwasempty' #djmwords contains the amount of words in each sentence #djmwords_total is the total word count between all the samples djmwords = [6, 15, 22, 17, 26, 29, 5, 8, 1, 3, 5, 19, 25, 18, 16, 17, 20, 25, 18, 5] djmwords_total = sum(djmwords) avgWORDS_per_SENTENCE_DJMACHALE = (djmwords_total/20) #Each variable becomes the total number of letters in each sentence djmachale_1 = len(djmachale_1) djmachale_2 = len(djmachale_2) djmachale_3 = len(djmachale_3) djmachale_4 = len(djmachale_4) djmachale_5 = len(djmachale_5) djmachale_6 = len(djmachale_6) djmachale_7 = len(djmachale_7) djmachale_8 = len(djmachale_8) djmachale_9 = len(djmachale_9) djmachale_10 = len(djmachale_10) djmachale_11 = len(djmachale_11) djmachale_12 = len(djmachale_12) djmachale_13 = len(djmachale_13) djmachale_14 = len(djmachale_14) djmachale_15 = len(djmachale_15) djmachale_16 = len(djmachale_16) djmachale_17 = len(djmachale_17) djmachale_18 = len(djmachale_18) djmachale_19 = len(djmachale_19) djmachale_20 = len(djmachale_20) #DJMACHALE_TOTAL is the total letter count between all the samples DJ_Machale = [djmachale_1, djmachale_2, djmachale_3, djmachale_4, djmachale_5, djmachale_6, djmachale_7, djmachale_8, djmachale_9, djmachale_10, djmachale_11, djmachale_12, djmachale_13, djmachale_14, djmachale_15, djmachale_16, djmachale_17, djmachale_18, djmachale_19, djmachale_20] DJMACHALE_TOTAL = (djmachale_1+djmachale_2+djmachale_3+djmachale_4+djmachale_5+djmachale_6+djmachale_7+djmachale_8+djmachale_9+djmachale_10+djmachale_11+djmachale_12+djmachale_13+djmachale_14+djmachale_15+djmachale_16+djmachale_17+djmachale_18+djmachale_19+djmachale_20) avgLETTERS_per_SENTENCE_DJMACHALE = (DJMACHALE_TOTAL/20) avgLETTERS_per_WORD_DJMACHALE = (DJMACHALE_TOTAL/djmwords_total) #-- #Suzanne Collins - The Hunger Games #The Hunger Games #Page 103 suzannecollins_1 = 'AsIstridetowardtheelevatorIflingmybowtoonesideandmyquivertotheother' suzannecollins_2 = 'IbrushpastthegapingAvoxeswhoguardtheelevatorsandhitthenumbertwelvebuttonwithmyfist' suzannecollins_3 = 'ThedoorsslidetogetherandIzipupward' suzannecollins_4 = 'Iactuallymakeitbacktomyfloorbeforethetearsstartrunningdownmycheeks' suzannecollins_5 = 'IcanheartheotherscallingmefromthesittingroombutIflydownthehallintomyroomboltthedoorandflingmyselfontomybed' suzannecollins_6 = 'ThenIreallybegintosob' suzannecollins_7 = 'NowIvedoneit' suzannecollins_8 = 'NowIveruinedeverything' suzannecollins_9 = 'IfIdevenstoodaghostofachanceitvanishedwhenIsentt
Re: Need Help with Programming Science Project
On Saturday, January 25, 2014 8:12:41 AM UTC+5:30, [email protected] wrote: > Alright. I have the code here. Now, I just want to note that the code was not > designed to work "quickly" or be very well-written. It was rushed, as I only > had a few days to finish the work, and by the time I wrote the program, I > hadn't worked with Python (which I never had TOO much experience with > anyways) for a while. (About a year, maybe?) It was a bit foolish to take up > the project, but here's the code anyways: E! If you (or anyone with basic python experience) rewrites that code, it will become 1/50th the size and all that you call 'code' will reside in data files. That can mean one of json, xml, yml, ini, pickle, ini, csv etc If you need further help in understanding/choosing, post back -- https://mail.python.org/mailman/listinfo/python-list
Trying to understand this moji-bake
I have an unexpected display error when dealing with Unicode strings, and
I cannot understand where the error is occurring. I suspect it's not
actually a Python issue, but I thought I'd ask here to start.
Using Python 3.3, if I print a unicode string from the command line, it
displays correctly. I'm using the KDE 3.5 Konsole application, with the
encoding set to the default (which ought to be UTF-8, I believe, although
I'm not completely sure). This displays correctly:
[steve@ando ~]$ python3.3 -c "print(u'ñøλπйж')"
ñøλπйж
Likewise for Python 3.2:
[steve@ando ~]$ python3.2 -c "print('ñøλπйж')"
ñøλπйж
But using Python 2.7, I get a really bad case of moji-bake:
[steve@ando ~]$ python2.7 -c "print u'ñøλπйж'"
ñøλÏйж
However, interactively it works fine:
[steve@ando ~]$ python2.7 -E
Python 2.7.2 (default, May 18 2012, 18:25:10)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print u'ñøλπйж'
ñøλπйж
This occurs on at least two different machines, one using Centos and the
other Debian.
Anyone have any idea what's going on? I can replicate the display error
using Python 3 like this:
py> s = 'ñøλπйж'
py> print(s.encode('utf-8').decode('latin-1'))
ñøλÏйж
but I'm not sure why it's happening at the command line. Anyone have any
ideas?
--
Steven
--
https://mail.python.org/mailman/listinfo/python-list
Re: Need Help with Programming Science Project
On Friday, January 24, 2014 7:06:55 PM UTC-8, Rustom Mody wrote: > On Saturday, January 25, 2014 8:12:41 AM UTC+5:30, [email protected] wrote: > > > Alright. I have the code here. Now, I just want to note that the code was > > not designed to work "quickly" or be very well-written. It was rushed, as I > > only had a few days to finish the work, and by the time I wrote the > > program, I hadn't worked with Python (which I never had TOO much experience > > with anyways) for a while. (About a year, maybe?) It was a bit foolish to > > take up the project, but here's the code anyways: > > > > > > > > E! > > > > If you (or anyone with basic python experience) rewrites that code, it will > become > > 1/50th the size and all that you call 'code' will reside in data files. > > > > That can mean one of json, xml, yml, ini, pickle, ini, csv etc > > > > If you need further help in understanding/choosing, post back I know. I'm kind of ashamed of the code, but it does the job I need it to up to a certain point, where it for some reason continually gives me Suzanne Collins as the author. It always gives three points to her name in the AUTHOR_SCOREBOARD list. The code, though, is REALLY bad. I'm trying to simply get it to do the things needed for the program. If I could get it to actually calculate the "points" for AUTHOR_SCOREBOARD properly, then all my problems would be solved. Luckily, I'm not being graded on the elegance or conciseness of my code. Thank you for the constructive criticism, though I am really seeking help with my little problem involving that dang scoreboard. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: generate De Bruijn sequence memory and string vs lists
Vincent Davis wrote: True, the "all you want is a mapping" is not quite true. I actually plan to plot frequency (the number of times an observed sub sequence overlaps a value in the De Bruijn sequence) The way the sub sequences overlap is important to me and I don't see a way go from base-k (or any other base) to the index location in the De Bruijn sequence. i.e. a decoding algorithm. So the order or position in which the subsequences appear in the de Bruijn sequence is important? Can you explain more about what you're trying to do? Maybe give a scaled-down example? Whatever it is, it seems like there should be a more efficient way than materialising the whole umpteen-gigabyte sequence. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Trying to understand this moji-bake
On 25Jan2014 04:37, Steven D'Aprano
wrote:
> I have an unexpected display error when dealing with Unicode strings, and
> I cannot understand where the error is occurring. I suspect it's not
> actually a Python issue, but I thought I'd ask here to start.
>
> Using Python 3.3, if I print a unicode string from the command line, it
> displays correctly. I'm using the KDE 3.5 Konsole application, with the
> encoding set to the default (which ought to be UTF-8, I believe, although
> I'm not completely sure).
There are at least 2 layers: the encoding python is using for
transcription to the terminal and the decoding the terminal is
making of the byte stream to decide what to display.
The former can be printed with:
import sys
print(sys.stdout.encoding)
The latter depends on your desktop settings and KDE settings I
guess. I would hope the Konsole will decide based on your environment
settings. Running the shell command:
locale
will print the settings derived from that. Provided your environment
matches that which invoked the Konsole, that should be informative.
But I expect the Konsole is decoding using UTF-8 because so much
else works for you already.
I would point out that you could perhaps debug with something like this:
python2.7 . | od -c
which will print the output bytes. By printing to the terminal,
you're letting the terminal's decoding get in your way. It is fine
for seeing correct/incorrect results, but not so fine for seeing
the bytes causing them.
> This displays correctly:
> [steve@ando ~]$ python3.3 -c "print(u'ñøλπйж')"
> ñøλπйж
>
>
> Likewise for Python 3.2:
> [steve@ando ~]$ python3.2 -c "print('ñøλπйж')"
> ñøλπйж
>
> But using Python 2.7, I get a really bad case of moji-bake:
> [steve@ando ~]$ python2.7 -c "print u'ñøλπйж'"
> ñøλÏйж
>
> However, interactively it works fine:
[...]
Debug by printing sys.stdout.encoding at this point.
I do recall getting different output encodings depending on how
Python was invoked; I forget the pattern, but I also remember writing
some ghastly hack to work around it, which I can't find at the
moment...
Also see "man python2.7" in particular the PYTHONIOENCODING environment
variable. That might let you exert more control.
Cheers,
--
Cameron Simpson
ASCII n s. [from the greek] Those people who, at certain times of the year,
have no shadow at noon; such are the inhabitatants of the torrid zone.
- 1837 copy of Johnson's Dictionary
--
https://mail.python.org/mailman/listinfo/python-list
Re: Trying to understand this moji-bake
On Sat, Jan 25, 2014 at 3:37 PM, Steven D'Aprano wrote: > But using Python 2.7, I get a really bad case of moji-bake: > > [steve@ando ~]$ python2.7 -c "print u'ñøλπйж'" > ñøλÏйж What's 2.7's default source code encoding? I thought it was ascii, but maybe it's assuming (in the absence of a magic cookie) that it's Latin-1. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help with Programming Science Project
[email protected] Wrote in message: > Alright. I have the code here. Now, I just want to note that the code was not > designed to work "quickly" or be very well-written. It was rushed, as I only > had a few days to finish the work, and by the time I wrote the program, I > hadn't worked with Python (which I never had TOO much experience with > anyways) for a while. (About a year, maybe?) It was a bit foolish to take up > the project, but here's the code anyways: . > > > LPW_Comparisons = [avgLPW_DJ_EXAMPLE, avgLPW_SUZC_EXAMPLE, > avgLPW_SUZC_EXAMPLE] > avgLPW_Match = min(LPW_Comparisons) > > if avgLPW_Match == avgLPW_DJ_EXAMPLE: > DJMachalePossibility = (DJMachalePossibility+1) > > if avgLPW_Match == avgLPW_SUZC_EXAMPLE: > SuzanneCollinsPossibility = (SuzanneCollinsPossibility+1) > > if avgLPW_Match == avgLPW_RICH_EXAMPLE: > RichardPeckPossibility = (RichardPeckPossibility+1) > > AUTHOR_SCOREBOARD = [DJMachalePossibility, SuzanneCollinsPossibility, > RichardPeckPossibility] > > #The author with the most points on them would be considered the program's > guess. > Match = max(AUTHOR_SCOREBOARD) > > print AUTHOR_SCOREBOARD > > if Match == DJMachalePossibility: > print "The author should be D.J. Machale." > > if Match == SuzanneCollinsPossibility: > print "The author should be Suzanne Collins." > > if Match == RichardPeckPossibility: > print "The author should be Richard Peck." > > > -- > Hopefully, there won't be any copyright issues. Like someone said, this > should be fair use. The problem I'm having is that it always gives Suzanne > Collins, no matter what example is put in. I'm really sorry that the code > isn't very clean. Like I said, it was rushed and I have little experience. > I'm just desperate for help as it's a bit too late to change projects, so I > have to stick with this. Also, if it's of any importance, I have to be able > to remove or add any of the "average letters per word/average letters per > sentence/average words per sentence things" to test the program at different > levels of strictness. I would GREATLY appreciate any help with this. Thank > you! > 1. When you calculate averages, you should be using floating point divide. avg = float (a) / b 2. When you subtract two values, you need an abs, because otherwise min () will hone in on the negative values. 3. Realize that having Match agree with more than one is not that unlikely. 4. If you want to vary what you call strictness, you're really going to need to learn about functions. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
should I transfer 'iterators' between functions?
take the following as an example, which could work well. But my concern is, will list 'l' be deconstructed after function return? and then iterator point to nowhere? def test(): l = [1, 2, 3, 4, 5, 6, 7, 8] return iter(l) def main(): for i in test(): print(i) -- https://mail.python.org/mailman/listinfo/python-list
Re: should I transfer 'iterators' between functions?
On Sat, Jan 25, 2014 at 5:37 PM, wrote: > take the following as an example, which could work well. > But my concern is, will list 'l' be deconstructed after function return? and > then iterator point to nowhere? > > def test(): > l = [1, 2, 3, 4, 5, 6, 7, 8] > return iter(l) > def main(): > for i in test(): > print(i) Perfectly safe. Python guarantees that nothing can ever point to "nowhere"; everything that might be looking for something else will hold a reference to it, so the thing referred to will hang around. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: should I transfer 'iterators' between functions?
On Fri, 24 Jan 2014 22:37:37 -0800, seaspeak wrote: > take the following as an example, which could work well. But my concern > is, will list 'l' be deconstructed after function return? and then > iterator point to nowhere? That would be a pretty awful bug for Python, since it would like lead to a core dump. But no, it works fine, as you can see by trying it at the interactive interpreter: py> def test(): ... L = [1, 2, 4, 8, 16] ... return iter(L) ... py> py> for i in test(): ... print(i) ... 1 2 4 8 16 In fact, we don't even need a function to see the same effect: py> L = [1, 2, 4, 8, 16] py> it = iter(L) py> del L py> L = "something else" py> for i in it: ... print(i) ... 1 2 4 8 16 Python keeps track of when objects are in use, and does not destroy them so long as it is in use. In the meantime, you can exit the function, unbind (delete) the variable, re-assign to something else, whatever, and you should never get a core dump. (I've only ever seen a single core dump in Python in 15+ years.) -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
"Chris Angelico" wrote in message
news:CAPTjJmpi-kvJAVs2gK+nH5n6q3REkJaKR=czerfzugdk8_v...@mail.gmail.com...
> On Fri, Jan 24, 2014 at 11:49 PM, Frank Millman
> wrote:
>>
>
[...]
I have realised that we unlikely to come to an agreement on this in the near
future, as our philosophies are completely different.
You have stated that your objective is to express as much as possible in
Python code.
I have stated that my objective is to express as little as possible in
Python code.
We would have to resolve that difference of opinion first, before discussing
our respective approaches in detail, and that is way beyond the scope of
this thread.
As a brief example of my approach, here is how I would write your simple
'About' box.
Here is your version -
mainwindow = GTK2.Window(0)->add(GTK2.Vbox(0,0)
->add(GTK2.Label("About Gypsum: big long multi-line string"))
->add(GTK2.HbuttonBox()
->add(GTK2.Button("Close"))
->add(GTK2.Button("Foobar"))
)
);
Here is my version -
Currently I do not have a widget for a multi-line label, so I just show
three separate lines. If I ever needed one, it would not take long to
create.
I took two screenshots, but I don't know the best way to upload and share
them. I found a site called tinypic, which works, but the screen is
cluttered with a lot of other stuff. Still, it shows what I want.
First, here is the screen as rendered in Internet Explorer (it works in
other browsers as well - even on my smart phone, though I have not done any
optimising for mobile devices yet) -
http://tinypic.com/r/ip15xx/5
Second, here is the screen designer, showing a portion of the screen
definition - one of the buttons. As you can see, the designer does not have
to worry about XML at all -
http://tinypic.com/r/1j7sdh/5
I am not claiming that I am 'right', or that this is a perfect solution. It
is just 'where I am' right now, after quite a long period of evolution, and
it is achieving a large portion of what I am aiming for, so I will press on
with my current approach for now.
Hopefully it will not take *too* long before I am in a position to release
something, and then I will be very interested in any feedback.
Thanks for the interesting discussion.
Frank
--
https://mail.python.org/mailman/listinfo/python-list
Re: Need Help with Programming Science Project
theguy wrote: I so far have three different authors in the program and have already put in the example text but for some reason, the program always leans toward one specific author, Suzanne Collins, no matter what insane number I try to put in or how much I tinker with the coding. It's obvious what's happening here: all the other authors have heavily borrowed from Suzanne Collins. You've created a plagiarism detector! :-) -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
On Sat, Jan 25, 2014 at 6:18 PM, Frank Millman wrote: > I have realised that we unlikely to come to an agreement on this in the near > future, as our philosophies are completely different. > > You have stated that your objective is to express as much as possible in > Python code. > > I have stated that my objective is to express as little as possible in > Python code. Ah but the question is *why* you want to minimize code. I write everything in code because it minimizes unnecessary coding - yes, that's right, I maximize code to minimize code :) - because all that code that isn't written also isn't debugged, isn't maintained, and isn't placing unnecessary restrictions on anything. What's the advantage of doing it in XML? Your GUI builder is all very well, but it could as easily write Python code as XML, so it doesn't give a strong incentive for XML. And personally, I think it's more likely to be a waste of effort, too, but that's more because a good GUI builder takes a *ton* of effort to build. That's time that has to be spent up-front, before you have experience with the system, before you _can get_ experience with the system - and, see above, it's code that has to be debugged and maintained. Every framework has to justify itself. Just "it lets people not write code" isn't enough unless not-writing-code can justify the costs. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help with Programming Science Project
theguy wrote: If I could get it to actually calculate the "points" for AUTHOR_SCOREBOARD properly, then all my problems would be solved. Have you tried getting it to print out the values it's getting for the scores, and comparing them with what you calculate by hand? -- Greg -- https://mail.python.org/mailman/listinfo/python-list
