module and namespace

2014-04-18 Thread Egon Frerich


I have a problem with a namespace. There is a module mptt (actally from
Django). If I import this module with the interpreter it tells me the
namespace:

Python 3.3.5 (default, Apr 12 2014, 23:34:20)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.





import mptt
print(mptt)





/mptt/__init__.py'>





 




If I import mptt in my program then there is no ImportError but the
namespace is broken:



(This is the output with print after the import).

What is the meaning? When does this happened?

Egon

























-- 
https://mail.python.org/mailman/listinfo/python-list


Re: module and namespace

2014-04-18 Thread Peter Otten
Egon Frerich wrote:

[Egon, please post in plain test, not html. Thank you]

> I have a problem with a namespace. There is a module mptt (actally from
> Django). If I import this module with the interpreter it tells me the
> namespace:
> 
> Python 3.3.5 (default, Apr 12 2014, 23:34:20)
> [GCC 4.6.3] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> 
> import mptt
> print(mptt)
> 
> 
> 
> 
> If I import mptt in my program then there is no ImportError but the
> namespace is broken:
> 
> 
> 
> (This is the output with print after the import).
> 
> What is the meaning? When does this happened?

Basically Python 3 allows for packages to omit the __init__.py

$ mkdir aaa
$ python3 -c'import aaa; print(aaa)'

$ touch aaa/__init__.py
$ python3 -c'import aaa; print(aaa)'


Namespace packages have advantages when you want to merge submodules from 
multiple places into one package. See 
 for the details.

Your actual problem is probably that the parent directory for the mptt 
package is not in your sys.path, but an unrelated directory with a mptt 
subdirectory (that may not contain any python code) is. This is the 
disadvantage of namespace packages -- any old directory may be mistaken for 
a package.

As to fixing the problem -- I don't know much about django, but you may need 
to invoke the interactive interpreter with

$ python3 manage.py shell


-- 
https://mail.python.org/mailman/listinfo/python-list


TeX $\times$ symbol not working in matplotlib?

2014-04-18 Thread gwhite
Hi,

I am trying to understand how to get the TeX "\times" symbol to work.  It is in 
the title() string in the code I pasted in.  The "\circ" symbol seems fine, by 
comparison.  "\times" ends up as "imes" in the figure title.

I am probably doing something dumb (hey, maybe a lot of dumb things!), but if 
you can spot and describe my mistake, I would be quite happy about that.

Thank you.

# (Using Python 2.7.5 via pythonxy.  w7-64)

--
import numpy as np
import matplotlib.pyplot as plt

Qs_rr = np.array([0.])
Qs_ri = np.array([0.])
Es_rr = np.array([-6.352844845095E-02,\
  -6.352844845095E-02,\
  -9.917112781473E-01,\
  -1.008084892264E+00,\
  -5.534164139252E-02,\
  -5.534164139252E-02])
Es_ri = np.array([ 9.329580097745E-01,\
  -9.329580097745E-01,\
   0.E+00,\
   0.E+00,\
   1.070772729531E+00,\
  -1.070772729531E+00]) 
plt.hold(False)
figs_open = plt.get_fignums()
axes_obj=plt.figure(figs_open[0]).gca()
lh1 = plt.plot(Qs_rr, Qs_ri, 'ro',\
   Es_rr, Es_ri, 'rx')
lh1[0].set_markerfacecolor('w')
lh1[0].set_markeredgecolor('r')
lh1[0].set_markersize(9.0)
lh1[0].set_markeredgewidth(0.75)
lh1[1].set_markersize(9.0)
lh1[1].set_markeredgewidth(0.75)
plt.axis([-1.2, 0.2, -1.2, 1.2])
plt.grid(True)
plt.title('$\mathrm{poles}$ $(\times)$ \
   $\mathrm{\&}$ $\mathrm{zeros}$ \
   $(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',\
   fontsize=16)
plt.xlabel(r'$\sigma$', fontsize=16)
plt.ylabel(r'$\mathrm{j}\omega$', fontsize=16)
plt.show()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TeX $\times$ symbol not working in matplotlib?

2014-04-18 Thread Chris “Kwpolska” Warrick
On Fri, Apr 18, 2014 at 6:18 PM, gwhite  wrote:
> I am trying to understand how to get the TeX "\times" symbol to work.  It is 
> in the title() string in the code I pasted in.  The "\circ" symbol seems 
> fine, by comparison.  "\times" ends up as "imes" in the figure title.
>
> I am probably doing something dumb (hey, maybe a lot of dumb things!), but if 
> you can spot and describe my mistake, I would be quite happy about that.

> plt.title('$\mathrm{poles}$ $(\times)$ \
>$\mathrm{\&}$ $\mathrm{zeros}$ \
>$(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',\
>fontsize=16)

You’re using a regular string.  In which backspaces can be used in
escapes.  \t is one of those escapes, it is the tab character.  In
order to fix, add the letter "r" before the opening quote.  Like this:

> plt.title(r'$\mathrm{poles}$ $(\times)$ \
>$\mathrm{\&}$ $\mathrm{zeros}$ \
>$(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',\
>fontsize=16)

Moreover, in the next two things, you already did it right in the first place:

> plt.xlabel(r'$\sigma$', fontsize=16)
> plt.ylabel(r'$\mathrm{j}\omega$', fontsize=16)

-- 
Chris “Kwpolska” Warrick 
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TeX $\times$ symbol not working in matplotlib?

2014-04-18 Thread gwhite
On Friday, April 18, 2014 9:24:55 AM UTC-7, Chris "Kwpolska" Warrick wrote:
> On Fri, Apr 18, 2014 at 6:18 PM, gwhite  wrote:
> 
> > I am trying to understand how to get the TeX "\times" symbol to work.  It 
> > is in the title() string in the code I pasted in.  The "\circ" symbol seems 
> > fine, by comparison.  "\times" ends up as "imes" in the figure title.
> >
> > I am probably doing something dumb (hey, maybe a lot of dumb things!), but 
> > if you can spot and describe my mistake, I would be quite happy about that.
> 
> > plt.title('$\mathrm{poles}$ $(\times)$ \
> >$\mathrm{\&}$ $\mathrm{zeros}$ \
> >$(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',\ 
> >fontsize=16)
> 
> You're using a regular string.  In which backspaces can be used in
> escapes.  \t is one of those escapes, it is the tab character.  In
> order to fix, add the letter "r" before the opening quote.  Like this:
>  
> > plt.title(r'$\mathrm{poles}$ $(\times)$ \
> >$\mathrm{\&}$ $\mathrm{zeros}$ \
> >$(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',\
> >fontsize=16)
>
> Moreover, in the next two things, you already did it right in the first place:
> 
> > plt.xlabel(r'$\sigma$', fontsize=16)
> > plt.ylabel(r'$\mathrm{j}\omega$', fontsize=16)


Thanks Chris!  That worked.

I faked myself out since the $(\circ)$ worked *without* the little r prefix. I 
was blind to it. I guess the difference must be there is no \c thingy to 
override \circ, so it just does the circle.

Thanks for the note on how the r prefix works. I knew I would screw myself 
sooner or later on that.

Getting regular text mixed with math text, but with the same font (in regular 
or italic) is a bit clumsy, I suppose. (I mean getting the spaces in.) At least 
I can do it. 

I did this too, and it also seems to work:

plt.title(' '.join([r'$\mathrm{poles}$', r'$(\times)$',\
r'$\mathrm{\&}$', r'$\mathrm{zeros}$',
r'$(\circ)$',  r'$\mathrm{of}$',\
r'$T(s)T(-s)$']), fontsize=16)

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TeX $\times$ symbol not working in matplotlib?

2014-04-18 Thread Peter Otten
gwhite wrote:

> plt.title(' '.join([r'$\mathrm{poles}$', r'$(\times)$',\
> r'$\mathrm{\&}$', r'$\mathrm{zeros}$',
> r'$(\circ)$',  r'$\mathrm{of}$',\
> r'$T(s)T(-s)$']), fontsize=16)

Note that adjacent string literals on the same line or inside parentheses 
are automatically concatenated by the compiler. So you may write the above 
as

plt.title(
r'$\mathrm{poles}$ $(\times)$ '
r'$\mathrm{\&}$ $\mathrm{zeros}$ '
r'$(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',
fontsize=16)

Even if you leave everything else as is you don't need any backslashes at 
the end of the line.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re:TeX $\times$ symbol not working in matplotlib?

2014-04-18 Thread Dave Angel
gwhite  Wrote in message:
> Hi,
> 
> I am trying to understand how to get the TeX "\times" symbol to work.  It is 
> in the title() string in the code I pasted in.  The "\circ" symbol seems 
> fine, by comparison.  "\times" ends up as "imes" in the figure title.
> 
> I am probably doing something dumb (hey, maybe a lot of dumb things!), but if 
> you can spot and describe my mistake, I would be quite happy about that.
> 

You want a raw string,  as you did correctly in two other places
 in the code. A raw string tells Python not to use the backslash
 as an escape. 

(Chris said backspace,  but he meant backslash)

You specify raw string by the letter r just before the quote. 

> > plt.title('$\mathrm{poles}$ $(\times)$ \
>$\mathrm{\&}$ $\mathrm{zeros}$ \
>$(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',\
>fontsize=16)
> 

Change to:

plt.title(r'$\mathrm{poles}$ $(\times)$ \
$\mathrm{\&}$ $\mathrm{zeros}$ \
$(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',\
fontsize=16)

-- 
DaveA

-- 
https://mail.python.org/mailman/listinfo/python-list


module and namespace

2014-04-18 Thread Egon Frerich
If I use the interpreter I get:

Python 3.3.5 (default, Apr 12 2014, 23:34:20)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mptt
>>> print(mptt)

>>>

But if I import mptt in my program the print-statement gives



What is the meaning? When does this happened?

Egon

-- 
https://mail.python.org/mailman/listinfo/python-list


module and namespace

2014-04-18 Thread Egon Frerich
If I use the interpreter I get:

Python 3.3.5 (default, Apr 12 2014, 23:34:20)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mptt
>>> print(mptt)

>>>

But if I import mptt in my program the print-statement gives



What is the meaning? When does this happened?

Egon



smime.p7s
Description: S/MIME Cryptographic Signature
-- 
https://mail.python.org/mailman/listinfo/python-list


module and namespace

2014-04-18 Thread Egon Frerich
I have a problem with a namespace. There is a module mptt (actally from
Django). If I import this module with the interpreter it tells me the
namespace:

Python 3.3.5 (default, Apr 12 2014, 23:34:20)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mptt
>>> print(mptt)

>>>

If I import mptt in my program then there is no ImportError but the
namespace is broken:



(This is the output with print after the import).

What is the meaning? When does this happened?

Egon






















-- 
https://mail.python.org/mailman/listinfo/python-list


Re:module and namespace

2014-04-18 Thread Dave Angel
Egon Frerich  Wrote in message:
> I have a problem with a namespace. 
> 

So you started 4 separate threads to complain about it? Keep any
 further remarks on the thread where you got a useful response.
 


-- 
DaveA

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: module and namespace

2014-04-18 Thread Egon Frerich
Am 18.04.2014 21:18, schrieb Dave Angel:
> Egon Frerich  Wrote in message:
>> I have a problem with a namespace. 
>>
> 
> So you started 4 separate threads to complain about it? Keep any
>  further remarks on the thread where you got a useful response.
>  
> 
> 


Excuse me for that. The mail server doesn't deliver the mails so I have
used another mail account (which sends the mail in HTML - soory). Then
the mail server got unblocked so all emails were sent.

Sorry

Egon




smime.p7s
Description: S/MIME Cryptographic Signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TeX $\times$ symbol not working in matplotlib?

2014-04-18 Thread gwhite
On Friday, April 18, 2014 10:04:17 AM UTC-7, Peter Otten wrote:
> gwhite wrote:
>  
> > plt.title(' '.join([r'$\mathrm{poles}$', r'$(\times)$',\
> > r'$\mathrm{\&}$', r'$\mathrm{zeros}$',
> > r'$(\circ)$',  r'$\mathrm{of}$',\
> > r'$T(s)T(-s)$']), fontsize=16)
>  
> Note that adjacent string literals on the same line or inside parentheses 
> are automatically concatenated by the compiler. So you may write the above 
> as
>
> plt.title(
> r'$\mathrm{poles}$ $(\times)$ '
> r'$\mathrm{\&}$ $\mathrm{zeros}$ '
> r'$(\circ)$ $\mathrm{of}$ $T(s)T(-s)$',
> fontsize=16)
>  
> Even if you leave everything else as is you don't need any backslashes at 
> the end of the line.

Well even if it had been right, I omitted one (backslash). I'm such a 
newb/hack. lol.  No animals were harmed.

Yeah, I have noticed that they don't seem to be needed, but I think I remember 
reading "someplace-somewhere" that a backslash means a line continuation, and 
perhaps I saw some author put them in.  So I did it out of trying to be 
"strict."

I'm not sure when a backslash continuation might be needed, or if that 
requirement has been designed out of Python.

Anyway, thanks to all for the notes!
-- 
https://mail.python.org/mailman/listinfo/python-list


Why Python 3?

2014-04-18 Thread Anthony Papillion
Hello Everyone,

So I've been working with Python for a while and I'm starting to take
on more and more serious projects with it. I've been reading a lot
about Python 2 vs Python 3 and the community kind of seems split on
which should be used.

Some say 'Python 3 is the future, use it for everything now' and other
say 'Python 3 is the future but you can't do everything in it now so
use Python 2'.

What is the general feel of /this/ community? I'm about to start a
large scale Python project. Should it be done in 2 or 3? What are the
benefits, aside from the 'it's the future' argument?

Thanks,
Anthony
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TeX $\times$ symbol not working in matplotlib?

2014-04-18 Thread Larry Hudson

On 04/18/2014 04:14 PM, gwhite wrote:
[snip]

Yeah, I have noticed that they don't seem to be needed, but I think I remember reading 
"someplace-somewhere" that
a backslash means a line continuation, and perhaps I saw some author put them in.  So I did it 
out of trying to be "strict."


I'm not sure when a backslash continuation might be needed, or if that 
requirement has been designed out of Python.



['they' meaning trailing backslashes]

No, 'they' are still definitely in Python, but can usually be avoided.

As already mentioned, strings are automatically concatenated if they are separated by only 
whitespace (spaces/tabs/newlines).  But there is a difference between this concatenation and 
using a trailing backslash.  For example:


print('this, that, '
'the other')

gives -> 'this, that, the other'

print('this, that, \
the other')

gives -> 'this, that, the other'

The leading whitespace in the second example is significant, but is ignored in 
the first.

The other places you can avoid the trailing backslash is within brackets, ie. 
(), [] or {}.
Here you can split at any 'natural' position, that is following a comma, dot or 
an operator.

['spam',
'eggs',
'bacon']

gives -> ['spam', 'eggs', 'bacon']

-
[2 +
 3,
  'spam']

gives -> [5, 'spam']

-
print('this' and
'that' or
'other')

gives -> 'that'

-
print('{}'.
format('spam'))

gives -> 'spam'

These examples are somewhat contrived, but they do show what I'm talking about.

Of course, you can still use the trailing backslash method, but when you can avoid it it usually 
looks cleaner.  Besides simply using either method to split long lines, it is often used to line 
things up, either for the appearance or for documentation.  Here is a dictionary example of what 
I mean (and the backslash method will NOT work here):


d = {1 : 'one',#  Describe this key/value pair
 2 : 'two',#  Describe this one
 3 : 'three'   #  Etc.
}

Play around in the interactive mode to check out how this splitting works.

 -=- Larry -=-

--
https://mail.python.org/mailman/listinfo/python-list


Re: Why Python 3?

2014-04-18 Thread Ryan Hiebert
If you are starting a new project, I'd highly encourage you to use Python
3. It is a stable, well supported, and beautiful language, and gives you
the full power of the innovation that is current in the Python world.
Python 2 is still well supported (for a while to come), but you won't have
the same access to new features and ideas that you would on Python 3.

The only reason that I'd still be on Python 2 is if I absolutely had to use
a library that for some reason is not yet working on Python 3. Even then,
I'd work hard to try and write it in Python 3 style Python 2, because I'd
want to be on Python 3 as soon as possible.


On Fri, Apr 18, 2014 at 10:28 PM, Anthony Papillion wrote:

> Hello Everyone,
>
> So I've been working with Python for a while and I'm starting to take
> on more and more serious projects with it. I've been reading a lot
> about Python 2 vs Python 3 and the community kind of seems split on
> which should be used.
>
> Some say 'Python 3 is the future, use it for everything now' and other
> say 'Python 3 is the future but you can't do everything in it now so
> use Python 2'.
>
> What is the general feel of /this/ community? I'm about to start a
> large scale Python project. Should it be done in 2 or 3? What are the
> benefits, aside from the 'it's the future' argument?
>
> Thanks,
> Anthony
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why Python 3?

2014-04-18 Thread Andrew Berg
On 2014.04.18 22:28, Anthony Papillion wrote:
> What is the general feel of /this/ community? I'm about to start a
> large scale Python project. Should it be done in 2 or 3? What are the
> benefits, aside from the 'it's the future' argument?
Python 3 is not the future; it is the present. If you're developing an 
application, just use Python 3.4 and don't look back unless you
absolutely positively *need* one of the big libraries that doesn't fully 
support Python 3 yet. The smaller ones either support it or have
been replaced, and the few remaining (e.g., Twisted, Django) are getting there. 
Python 2 still exists because there are very large existing
projects (some public, some private) that are not able to use Python 3 for some 
reason (like heavy dependence on a third-party that doesn't
support Python 3). If you are developing a new library, the decision is not 
likely going to be easy, but in general, I'd say the larger it
is, the more you should lean toward not having Python 2 support. Of course, 
there are going to be other factors such as your audience and
what, if any, third-party libraries you will need yourself. It's an awkward 
time to write a new library since supporting both 2 and 3 is a
major pain, and Python 2 is eventually going away, but you will still have a 
significant amount of people who will want to use the library
with things that can't support Python 3.

Use Python 2 if you must, but know that you will end up needing to migrate to 
Python 3 eventually.
It used to be that support for Python 3 among third-party libraries was small, 
but that is no longer true: http://python3wos.appspot.com/
-- 
CPython 3.4.0 | Windows NT 6.2.9200 / FreeBSD 10.0
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why Python 3?

2014-04-18 Thread Ethan Furman

On 04/18/2014 08:28 PM, Anthony Papillion wrote:


What is the general feel of /this/ community? I'm about to start a
large scale Python project. Should it be done in 2 or 3? What are the
benefits, aside from the 'it's the future' argument?


This community is also split.  ;)

Use Python 3 if you can.  The best reason not to is if you have some critical library that you absolutely need and it's 
not yet available on 3.  In which case, program as if your code base was going to run on both 2 and 3 so you can update 
easily once your dependency upgrades.


--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Why Python 3?

2014-04-18 Thread Paul Rubin
Anthony Papillion  writes:
> Some say 'Python 3 is the future, use it for everything now' and other
> say 'Python 3 is the future but you can't do everything in it now so
> use Python 2'.

Python 3 is generally better than Python 2, except for a few packages
that haven't been ported.

That said, I don't know anyone who actually uses Python 3.  I don't
think it's a matter of wanting to use some problematic package, or
having particular technical concerns.  It's just that the improvement
from 2 to 3 is rather small, and 2 works perfectly well and people are
used to it, so they keep using it.  There are nice tools that
help port your codebase from 2 to 3 with fairly little effort.
But, you can also keep your codebase on 2 with zero effort.
So people choose zero over fairly little.

If you're starting a new project and you get to choose between 2 and 3,
other things equal I'd say use 3.  I've kept using 2 basically because
it's the path of least resistance.  I'm somewhat following the 3
situation and of course I'd use 3 if I were doing something that
benefited from it, but so far it hasn't been an issue.

Eventually the main Linux distros will include 3 instead of 2 by
default, and we'll probably see more migration then.  Right now I type
"python" and get 2, so I use it.
-- 
https://mail.python.org/mailman/listinfo/python-list