Re: subprocess check_output
On Thu, Jan 7, 2016 at 8:33 PM, me wrote: > On 2016-01-05, Chris Angelico wrote: >> Oh, and then you keep editing and save again? Nah, I've *never* done >> that... Never! > > I'm quite surprised, buddy. You should definitely try. I know, right! It's so exciting to suddenly discover that you have two separate copies of a piece of code, and that one of them isn't where you think it is... makes life so interesting! Serious suggestion for people who run into weirdness: Sometimes it helps to make a deliberate and obvious syntax error (misuse a keyword, break the indentation, put a mass of symbols in someplace), just to see that your code is getting parsed. If it doesn't trigger an error, well, your deployment is failing somewhere. CSS gurus suggest, along similar lines, changing the background color of something to red. Saves ever so much fiddling around - instead of asking "why doesn't my padding work in IE?", you ask the correct question of "why isn't my CSS file being read?", upon which you discover that you were referencing it from the wrong directory. True story. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: subprocess check_output
Marko Rauhamaa : > Chris Angelico : > >> you ask the correct question of "why isn't my CSS file being read?" > > TL;DR Sorry, getting confused with homonyms: >> CSS gurus suggest, along similar lines, changing the background color >> of something to red. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Fast pythonic way to process a huge integer list
[email protected] wrote: > I have a list of 163.840 integers. What is a fast & pythonic way to > process this list in 1,280 chunks of 128 integers? What kind of processing do you have in mind? If it is about numbercrunching use a numpy.array. This can also easily change its shape: >>> import numpy >>> a = numpy.array(range(12)) >>> a array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) >>> a.shape = (3, 4) >>> a array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) If it's really only(!) under a million integers slicing is also good: items = [1, 2, ...] CHUNKSIZE = 128 for i in range(0, len(items), CHUNKSIZE): process(items[start:start + CHUNKSIZE]) If the "list" is really huge (your system starts swapping memory) you can go completely lazy: from itertools import chain, islice def chunked(items, chunksize): items = iter(items) for first in items: chunk = chain((first,), islice(items, chunksize-1)) yield chunk for dummy in chunk: # consume items that may have been skipped # by your processing pass def produce_items(file): for line in file: yield int(line) CHUNKSIZE = 128 # this could also be "huge" # without affecting memory footprint with open("somefile") as file: for chunk in chunked(produce_items(file), CHUNKSIZE): process(chunk) -- https://mail.python.org/mailman/listinfo/python-list
Re: subprocess check_output
On Thu, Jan 7, 2016 at 9:14 PM, Marko Rauhamaa wrote: > Marko Rauhamaa : > >> Chris Angelico : >> >>> you ask the correct question of "why isn't my CSS file being read?" >> >> TL;DR > > Sorry, getting confused with homonyms: > > >>> CSS gurus suggest, along similar lines, changing the background color >>> of something to red. > > Oh. I think that wordplay was _exactly_ why the choice was red, rather than an equally-obvious yellow or green or blue or something. "If the body is red, the file was read". ChrisA -- https://mail.python.org/mailman/listinfo/python-list
True/False value testing
Hello For integer, 0 is considered False and any other value True A=0 A==False True A==True False A=1 A==False False A==True True It works fine For string, "" is considered False and any other value True, but it doesn't work A = "" A==False False A==True False A = 'Z' A==False False A==True False What happens ??? thx -- https://mail.python.org/mailman/listinfo/python-list
Re: True/False value testing
ast wrote:
> Hello
>
> For integer, 0 is considered False and any other value True
>
A=0
A==False
> True
A==True
> False
A=1
A==False
> False
A==True
> True
>
> It works fine
But not the way you think:
>>> 0 == False
True
>>> 1 == True
True
>>> 2 == True
False
>>> 2 == False
False
0 equals False, 1 equals True, and any other integer equals neither, but
"is true in a boolean context", i. e.
>>> if 42: print("42 considered true")
...
42 considered true
> For string, "" is considered False and any other value True,
> but it doesn't work
In a similar way there is no string that equals True or False, but
the empty string "" is considered false in a boolean context while all other
strings are considered true:
>>> bool("")
False
>>> bool("whatever")
True
A = ""
A==False
> False
A==True
> False
A = 'Z'
A==False
> False
A==True
> False
>
>
> What happens ???
>
> thx
--
https://mail.python.org/mailman/listinfo/python-list
Re: True/False value testing
Chris Angelico : > However, none of these will compare *equal* to the Boolean values True > and False, save for the integers 1 and 0. In fact, True is a special > form of the integer 1, and False is a special form of the integer 0; Stirring the pot: >>> (2 < 3) is True True but is that guaranteed? Marko -- https://mail.python.org/mailman/listinfo/python-list
A newbie's doubt
Is Python's Tutorial (by Guido) a good and complete reference for the language? I mean, after reading it, should I have a good basis on Python? I've came from js and php, and already know the very basics of py. Thank you! -- https://mail.python.org/mailman/listinfo/python-list
Re: A newbie's doubt
On Thu, Jan 7, 2016 at 2:20 PM, Henrique Correa wrote: > Is Python's Tutorial (by Guido) a good and complete reference for the > language? I mean, after reading it, should I have a good basis on Python? > > I've came from js and php, and already know the very basics of py. > > Thank you! If by "good and complete" you mean "enough to write code in", then yes, I would say it is. If you mean "enough to write applications that you can sell for money", then it's probably insufficient; you'll want to also learn a few libraries, possibly including third-party ones like Flask/Django (to write web applications) or numpy/pandas (to write computational code) or matplotlib (to crunch numbers and make graphs). If, on the other hand, you mean "enough to understand how Python works internally", then no, it's not. It's not meant to go into that kind of detail. But you don't need to know that anyway. I would recommend going through that tutorial. You'll get a decent handle on how Python works. As a general rule, Python's object model is similar to what you'll know from JS; the scoping rules are different (instead of "var x;" to declare that x is local, you would have "global x" to declare that x is global - but you need declare only those globals that you assign to, not those you reference). As you go through it, write down some notes of everything that interests or confuses you; once you've completed the tutorial, go through your notes again. Some of what you've written down will now make perfect sense, and you can delete it; some will still confuse you, but you'll understand more of *why* it confuses you. So then you come back here to python-list with the bits that confuse you, and we'll be happy to explain stuff! ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to union nested Sets / A single set from nested sets?
On 7 January 2016 at 08:37, Steven D'Aprano wrote:
> On Thu, 7 Jan 2016 01:45 am, Oscar Benjamin wrote:
>
>> On 4 January 2016 at 02:40, mviljamaa wrote:
>>> I'm forming sets by set.adding to sets and this leads to sets such as:
>>>
>>> Set([ImmutableSet(['a', ImmutableSet(['a'])]), ImmutableSet(['b', 'c'])])
>>>
>>> Is there way union these to a single set, i.e. get
>>>
>>> Set(['a', 'b', 'c'])
>>
>> Where are you getting Set and ImmutableSet from? Is that sympy or
>> something?
>
> Set and ImmutableSet were the original versions from Python 2.3 before the
> builtins. They're still available up to Python 2.7 (gone in 3):
>
>
> py> import sets
> py> sets.Set
>
>
> but that's just for backwards compatibility, you should use the built-in
> versions if you can.
Okay, thanks Steve.
Then I translate the OP's problem as how to go from
S = set([frozenset(['a', frozenset(['a'])]), frozenset(['b', 'c'])])
to
set(['a', 'b', 'c'])
This is not just a union of the elements of the set since:
In [7]: {x for fs in S for x in fs}
Out[7]: set(['a', 'c', 'b', frozenset(['a'])])
The reason for this is that there are multiple levels of nesting. I
assume that the OP wants to recursively get all the elements from all
the nested sets and create a set out of those. Here's a breadth-first
search that can do that:
def flat_nested(tree):
flat = set()
stack = [iter(tree)]
while stack:
branch = stack.pop(0)
for x in branch:
if isinstance(x, frozenset):
stack.append(iter(x))
else:
flat.add(x)
return flat
And now:
In [15]: flat_nested(S)
Out[15]: set(['a', 'c', 'b'])
--
Oscar
--
https://mail.python.org/mailman/listinfo/python-list
Re: imshow keeps crashhing
I think I figured out the real problem, you can see my post here: http://stackoverflow.com/questions/34645512/scipy-imshow-conflict-with-el-capitan-sip-and-var-folders/34646093#34646093 Thanks again for helping to guide me in the right direction. -- https://mail.python.org/mailman/listinfo/python-list
Re: imshow keeps crashhing
On Wed, Jan 6, 2016, at 18:37, William Ray Wing wrote: > Is this a typo or did you really mean /private/vars? That is, did your > create a “vars” directory under /private at some point in the past > (pre-Yosemite)? The usual directory there would be /var > > In any case, the whole /private directory tree is now part of the SIP > (System Integrity Protection) system under Yosemite, and to open and > manipulate files there you will have to either turn SIP off or jump > through hoops. If you do a ls -al in /private, you will see that var is /private/var/folders/.. is for per-user temporary directories [default value of TMPDIR], and the directories in question are writable by the users and not affected by SIP. But it's hidden (since people aren't expected to actually want to navigate to their temporary files - how often do you actually go look for something in /tmp?). I would suggest creating his files in the desktop or documents folder if he wants to be able to interactively use the files. -- https://mail.python.org/mailman/listinfo/python-list
What meaning is 'from . import'
Hi, I see the following code. After searching around, I still don't know the meaning of '.'. Could you tell me that ? Thanks, from . import _hmmc from .utils import normalize -- https://mail.python.org/mailman/listinfo/python-list
Re: What meaning is 'from . import'
On Fri, Jan 8, 2016 at 3:50 AM, Robert wrote: > Hi, > > I see the following code. After searching around, I still don't know the > meaning of '.'. Could you tell me that ? Thanks, > > > > > > from . import _hmmc > from .utils import normalize That's called a package-relative import. https://www.python.org/dev/peps/pep-0328/ If you create a package called (let's be really creative here) "package", an external script could do this: from package import _hmmc from package.utils import normalize Within the package, you can say "from myself import stuff". It's exactly the same thing, only it doesn't repeat the package name. If you think of a package as a directory (which it often will be anyway), the dot is similar to the common notation for "current directory". ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about a class member
On Thursday, January 7, 2016 at 12:24:53 PM UTC-5, Robert wrote: > Hi, > > I am using a download package. When I read its code, see below please, I > don't know what 'sample' is: > > > -- > model = hmm.GaussianHMM(n_components=4, covariance_type="full") > > model.startprob_ = startprob > model.transmat_ = transmat > model.means_ = means > model.covars_ = covars > > # Generate samples > X, Z = model.sample(50) > - > > When I read its (class) definition, I find the following part (which may not > be sure 100% the above origination yet, but it is the only line being > 'sample'). > // > self.gmms_ = [] > for x in range(self.n_components): > if covariance_type is None: > gmm = GMM(n_mix) > else: > gmm = GMM(n_mix, covariance_type=covariance_type) > self.gmms_.append(gmm) > > def _init(self, X, lengths=None): > super(GMMHMM, self)._init(X, lengths=lengths) > > for g in self.gmms_: > g.set_params(init_params=self.init_params, n_iter=0) > g.fit(X) > > def _compute_log_likelihood(self, X): > return np.array([g.score(X) for g in self.gmms_]).T > > def _generate_sample_from_state(self, state, random_state=None): > return self.gmms_[state].sample(1, > random_state=random_state).flatten() > > > The above code looks like self.gmms is a list, which has an attribute > 'sample'. But when I play with a list, there is no 'sample' attribute. > > .. > a=[1, 32.0, 4] > > a > Out[68]: [1, 32.0, 4] > > type(a) > Out[69]: list > > a[0].sample(1,5) > --- > AttributeErrorTraceback (most recent call last) > in () > > 1 a[0].sample(1,5) > > AttributeError: 'int' object has no attribute 'sample' > > a[1].sample(1,5) > --- > AttributeErrorTraceback (most recent call last) > in () > > 1 a[1].sample(1,5) > > AttributeError: 'float' object has no attribute 'sample' > > > What is 'sample' do you think? > > Thanks, The code can be downloaded from: https://github.com/hmmlearn/hmmlearn/blob/master/examples/plot_hmm_sampling.py Hope it can help to answer my question. Thanks again. -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about a class member
In Robert writes: > I am using a download package. When I read its code, see below please, I > don't know what 'sample' is: > -- > model = hmm.GaussianHMM(n_components=4, covariance_type="full") > model.startprob_ = startprob > model.transmat_ = transmat > model.means_ = means > model.covars_ = covars > # Generate samples > X, Z = model.sample(50) > - sample() is a method in the GaussianHMM class. (In this case, it's a method in the _BaseHMM class, from which GaussianHMM inherits.) -- John Gordon A is for Amy, who fell down the stairs [email protected] B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about a class member
On Fri, 8 Jan 2016 04:23 am, Robert wrote: > Hi, > > I am using a download package. When I read its code, see below please, I > don't know what 'sample' is: > > > -- > model = hmm.GaussianHMM(n_components=4, covariance_type="full") When I try running that code, I get an error: py> model = hmm.GaussianHMM(n_components=4, covariance_type="full") Traceback (most recent call last): File "", line 1, in NameError: name 'hmm' is not defined What's hmm? Where does it come from? Is it this? https://hmmlearn.github.io/hmmlearn/generated/hmmlearn.hmm.GaussianHMM.html It has a sample method here: https://hmmlearn.github.io/hmmlearn/generated/hmmlearn.hmm.GaussianHMM.html#hmmlearn.hmm.GaussianHMM.sample You should try googling for help before asking questions: https://duckduckgo.com/html/?q=hmm.GaussianHMM or use the search engine of your choice. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about a class member
On Thursday, January 7, 2016 at 5:06:07 PM UTC-5, Steven D'Aprano wrote: > On Fri, 8 Jan 2016 04:23 am, Robert wrote: > > > Hi, > > > > I am using a download package. When I read its code, see below please, I > > don't know what 'sample' is: > > > > > > -- > > model = hmm.GaussianHMM(n_components=4, covariance_type="full") > > > When I try running that code, I get an error: > > > py> model = hmm.GaussianHMM(n_components=4, covariance_type="full") > Traceback (most recent call last): > File "", line 1, in > NameError: name 'hmm' is not defined > > What's hmm? Where does it come from? Is it this? > > https://hmmlearn.github.io/hmmlearn/generated/hmmlearn.hmm.GaussianHMM.html > > It has a sample method here: > > https://hmmlearn.github.io/hmmlearn/generated/hmmlearn.hmm.GaussianHMM.html#hmmlearn.hmm.GaussianHMM.sample > > > You should try googling for help before asking questions: > > https://duckduckgo.com/html/?q=hmm.GaussianHMM > > or use the search engine of your choice. > > > -- > Steven Thanks. I just realized that my list assumption was wrong. I got that conclusion was incorrect. -- https://mail.python.org/mailman/listinfo/python-list
PyFladesk :: create GUI apps by Python and HTML, CSS and Javascript.
create multi platform desktop application by using Python, HTML, CSS and Javascript. source code is https://github.com/smoqadam/PyFladesk you can find RSS Reader app that made by PyFladesk in the following url : https://github.com/smoqadam/PyFladesk-rss-reader I'll waiting for your feedback. thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: A newbie's doubt
That's an awesome response! On Jan 7, 2016 6:35 AM, "Chris Angelico" wrote: > On Thu, Jan 7, 2016 at 2:20 PM, Henrique Correa wrote: > > Is Python's Tutorial (by Guido) a good and complete reference for the > > language? I mean, after reading it, should I have a good basis on Python? > > > > I've came from js and php, and already know the very basics of py. > > > > Thank you! > > If by "good and complete" you mean "enough to write code in", then > yes, I would say it is. > > If you mean "enough to write applications that you can sell for > money", then it's probably insufficient; you'll want to also learn a > few libraries, possibly including third-party ones like Flask/Django > (to write web applications) or numpy/pandas (to write computational > code) or matplotlib (to crunch numbers and make graphs). > > If, on the other hand, you mean "enough to understand how Python works > internally", then no, it's not. It's not meant to go into that kind of > detail. But you don't need to know that anyway. > > I would recommend going through that tutorial. You'll get a decent > handle on how Python works. As a general rule, Python's object model > is similar to what you'll know from JS; the scoping rules are > different (instead of "var x;" to declare that x is local, you would > have "global x" to declare that x is global - but you need declare > only those globals that you assign to, not those you reference). As > you go through it, write down some notes of everything that interests > or confuses you; once you've completed the tutorial, go through your > notes again. Some of what you've written down will now make perfect > sense, and you can delete it; some will still confuse you, but you'll > understand more of *why* it confuses you. So then you come back here > to python-list with the bits that confuse you, and we'll be happy to > explain stuff! > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Fast pythonic way to process a huge integer list
On Wednesday, 6 January 2016 18:37:22 UTC-8, [email protected] wrote: > I have a list of 163.840 integers. What is a fast & pythonic way to process > this list in 1,280 chunks of 128 integers? Thanks all for your valuable input - much appreciated! -- https://mail.python.org/mailman/listinfo/python-list
Re: A newbie's doubt
Às 03:20 de 07-01-2016, Henrique Correa escreveu: > Is Python's Tutorial (by Guido) a good and complete reference for the > language? Good yes. Complete no. I mean, after reading it, should I have a good basis on Python? Yes if you know how to program on another language. > HTH Paulo -- https://mail.python.org/mailman/listinfo/python-list
SUM only of positive numbers from array
Hi All, I should help... I want to calculate the sum of a positive number, for each row: x = ((mat_1 / s_1T)-(s_2 / total)) y = (np.sum(x > 0, axis=1)).reshape(-1, 1).tolist() However, this part of the code only calculation count, I need sum. Any ideas how to solve this problem? thanks in advance -- https://mail.python.org/mailman/listinfo/python-list
Re: PyFladesk :: create GUI apps by Python and HTML, CSS and Javascript.
I would definitely like to try out something like this - I am primarily a web developer, and, partly since am 100% blind, any form of GUI design is at times an issue for me, whereas I have been working with HTML markup layouts for almost 20 years now, but, which versions of python should this work with, and, what does it actually then use to generate/handle GUI interface? Ask since, some of the GUI frameworks are not too accessible themselves. Also, downloaded both the main master, and the RSS reader master images, but, both python 2.7 and python 3.4 tell me that they have no urllib2, and under 3.4, pip install can't find it either..? TIA Jacob Kruger Blind Biker Skype: BlindZA "Roger Wilco wants to welcome you...to the space janitor's closet..." On 2016-01-08 1:08 AM, Saeed Moqadam wrote: create multi platform desktop application by using Python, HTML, CSS and Javascript. source code is https://github.com/smoqadam/PyFladesk you can find RSS Reader app that made by PyFladesk in the following url : https://github.com/smoqadam/PyFladesk-rss-reader I'll waiting for your feedback. thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: PyFladesk :: create GUI apps by Python and HTML, CSS and Javascript.
On Fri, Jan 8, 2016 at 1:54 AM, jacob Kruger wrote: > > Also, downloaded both the main master, and the RSS reader master images, > but, both python 2.7 and python 3.4 tell me that they have no urllib2, and > under 3.4, pip install can't find it either..? > > TIA > Python 3 does not have urllib2. It is a Python 2 module that has been split across several modules in Python 3. However, are you sure you tried it with Python 2.7? -- Bernardo Sulzbach -- https://mail.python.org/mailman/listinfo/python-list
Re: PyFladesk :: create GUI apps by Python and HTML, CSS and Javascript.
Ok, double-checked again, and if force it to run under 2.7, then it complains about lack of pyQT4 - that's one of the issues was asking about relating to GUI frameworks - pyQT hasn't always worked too well under 2.7 in terms of accessibility API's in past, but, will 'see' if can get hold of that module for 2.7, and take it from there. Jacob Kruger Blind Biker Skype: BlindZA "Roger Wilco wants to welcome you...to the space janitor's closet..." On 2016-01-08 7:07 AM, Bernardo Sulzbach wrote: On Fri, Jan 8, 2016 at 1:54 AM, jacob Kruger wrote: Also, downloaded both the main master, and the RSS reader master images, but, both python 2.7 and python 3.4 tell me that they have no urllib2, and under 3.4, pip install can't find it either..? TIA Python 3 does not have urllib2. It is a Python 2 module that has been split across several modules in Python 3. However, are you sure you tried it with Python 2.7? -- https://mail.python.org/mailman/listinfo/python-list
extract script from executable made by pyinstaller?
Is it possible to extract (and view) the Python script from the Windows executable which was made by pyinstller? -- Ullrich Horlacher Server und Virtualisierung Rechenzentrum IZUS/TIK E-Mail: [email protected] Universitaet Stuttgart Tel:++49-711-68565868 Allmandring 30aFax:++49-711-682357 70550 Stuttgart (Germany) WWW:http://www.tik.uni-stuttgart.de/ -- https://mail.python.org/mailman/listinfo/python-list
