Re: configparser bug

2017-01-26 Thread Christos Malliopoulos
Thanx Peter for your prompt response.
I replaced tabs with spaces and had no problem reading the file.
I think however it is sth to correct in next versions

BR
Chris


On Wed, Jan 25, 2017 at 1:32 PM Peter Otten <[email protected]> wrote:

> Christos Malliopoulos wrote:
>
> > Hi,
> >
> > I run Ubuntu 16.04 LTS in a VM using VMWare Workstation on a Windows 10
> > host.
> > apt show python-configparser shows 3.3.0r2-2
> > On python 2.7.12 I use the following code:
> >
> > import configparser as cfg
> > root =
> > u'/'.join(os.path.split(os.path.abspath('cfg.py'))[0].split('/')[:-2])
> > cp = cfg.ConfigParser(interpolation = cfg.ExtendedInterpolation())
> > cp.read(os.path.abspath(os.path.join(root, u'config/sampling.cfg')))
>
> This looks confusing. Are you sure you are reading the right sampling.cfg?
>
> > cp.items('Sampling')
> >
> > sampling.cfg contains the following lines:
> > [Sampling]
> > nobs = 10
> > nzin = 4
> > nzout = 3
> > ndrops = 1
> >
> > inh = day,loc,z0,value
> > outh = day,loc,sku,value
> >
> > invalran = 1,1e3
> > outvalran = 1,1000
> >
> > cp.items(u'Sampling') prints the following:
> > [(u'nobs', u'10'),
> >  (u'nzin', u'4'),
> >  (u'nzout', u'3\nndrops = 1'),
> >  (u'inh', u'day,loc,z0,value'),
> >  (u'outh', u'day,loc,sku,value'),
> >  (u'invalran', u'1,1e3'),
> >  (u'outvalran', u'1,1000')]
> >
> > ndrops = 1 is not parsed correctly
>
> It looks like the parser does not expand tabs, and your problem may be
> mixing tabs and spaces:
>
> $ cat demo.py
> import configparser
>
> data = """\
> [Sampling]
> \talpha = 1
> \tbeta = 2
>  \tgamma = 3
> \tdelta = 4
> """
> print "what you see:"
> print data.expandtabs(4)
>
> print "what the parser sees:"
> print data.replace("\t", " ")
>
> with open("sampling.cfg", "w") as f:
> f.write(data)
>
> cp = configparser.ConfigParser(
> interpolation=configparser.ExtendedInterpolation()
> )
> cp.read("sampling.cfg")
> for item in cp.items('Sampling'):
> print item
> $ python demo.py
> what you see:
> [Sampling]
> alpha = 1
> beta = 2
> gamma = 3
> delta = 4
>
> what the parser sees:
> [Sampling]
>  alpha = 1
>  beta = 2
>   gamma = 3
>  delta = 4
>
> (u'alpha', u'1')
> (u'beta', u'2\ngamma = 3')
> (u'delta', u'4')
> $
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need reviews for my book on introductory python

2017-01-26 Thread Verde Denim
You would like us to volunteer to "review" your book that you'd like us 
to buy from you and that has already been published and used as a 
curriculum guide... If you'd like it reviewed by the Py community, how 
about making it available to us and allow us to edit it or suggest 
changes as needed? This, of course, would be for no-charge as we are 
using our time and resources to review your publication at no  cost to 
you. Thanks.



On 1/25/2017 9:25 PM, Sandeep Nagar wrote:

Hi,

A few month ago I wrote a book on introductory python based on my experinces 
while teaching python to Bachelor students of engineering. It is now available 
in e-book and paperback format at Amazon.

https://www.amazon.com/dp/1520153686

The book is written for beginners of python programming language and written in 
learn-by-doing manner. If some group members can review the same, it will be 
useful for myself to come up with an improved version.

Other similar books of mine are based on Octave and Scilab with following links:

https://www.amazon.com/dp/152015111X (Scilab)

https://www.amazon.com/dp/1520158106 (Octave)

If you are interested in open source computing, please have a look.

Also please do share the link for print books with your colleagues at other 
universities and recommend them for libraries and researchers, if you feel that 
they can be helpful to them.

Regards

Sandeep



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: Need reviews for my book on introductory python

2017-01-26 Thread BartC

On 26/01/2017 12:32, Verde Denim wrote:

You would like us to volunteer to "review" your book that you'd like us
to buy from you and that has already been published and used as a
curriculum guide... If you'd like it reviewed by the Py community, how
about making it available to us and allow us to edit it or suggest
changes as needed?


The amazon link lets you look at the first few pages free of charge.

That might be enough to form an opinion. (The first pages do include a 
Hello World program; unfortunately it's in C not Python!)



--
Bartc

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


Re: Need reviews for my book on introductory python

2017-01-26 Thread bob gailer

On 1/25/2017 9:25 PM, Sandeep Nagar wrote:

Hi,

A few month ago I wrote a book on introductory python based on my experinces 
while teaching python to Bachelor students of engineering. It is now available 
in e-book and paperback format at Amazon.

https://www.amazon.com/dp/1520153686

The book is written for beginners of python programming language and written in 
learn-by-doing manner. If some group members can review the same, it will be 
useful for myself to come up with an improved version.
I'd like to review it, but am reluctant to put out money for a copy! How 
about offering a review copy at no charge?


Other similar books of mine are based on Octave and Scilab with following links:

https://www.amazon.com/dp/152015111X (Scilab)

https://www.amazon.com/dp/1520158106 (Octave)

If you are interested in open source computing, please have a look.

Also please do share the link for print books with your colleagues at other 
universities and recommend them for libraries and researchers, if you feel that 
they can be helpful to them.

Regards

Sandeep



--
Image and video hosting by TinyPic
--
https://mail.python.org/mailman/listinfo/python-list


Re: How coding in Python is bad for you

2017-01-26 Thread Brandon McCaig
On Tue, Jan 24, 2017 at 07:31:18PM +, Ben Bacarisse wrote:
> The trouble is that I've been programming for so long that I
> can't remember what it's like to make block and/or indent
> errors.  Obviously I make typos but they don't survive more
> than a few seconds.

Agreed. In very rare circumstances (likely very tired) you might
make such a mistake without catching it, but typically you'll
catch it during testing, and code review is another chance to
catch it. Source control FTW. I think that a lot of these kinds
of problems happen to beginners and the beginners make the most
noise about how it will be a problem. I initially was against
Python's significant white-space, but in hindsight I can see how
it saves a bit of typing and is not necessarily any worse off.

Hell, considering the code that I have seen in the wild it might
even catch some extra errors that become syntax errors! It's not
at all rare for indentation to not match in languages that don't
require it to at least fit a pattern.

I think that an apples to apples comparison of an erroneous
indentation level would be comparing a misplaced brace:

foo {
bar;
}
baz;

wapz. Was that supposed to be "foo { bar; baz; }" or "foo { bar;
 } baz;" ? That's effectively the same problem that you might
have with Python code. The answer? Hopefully it's obvious when
looking at the code! If it's not, hopefully source control can
tell you. And if you can't be certain, *talk* to somebody.
There's no substitute for communication.

> In Python the editor could, for example, highlight the block
> you are typing in, so as soon as you leave the body of the 'if'
> it would stop being marked and the containing code would be
> highlighted.  Just moving the cursor up and down would show you
> what block everything is in.  I don't know if any editors help
> like this -- that's part of my reason to ask.

That's actually a pretty neat idea. I don't think I've ever
encoutered an editor that does (or if I have, it has either been
too long or so subtle that it doesn't stand out). I think that it
is a pretty good idea though.

I certainly find it useful to highlight matching braces in
editors, but it can be a pain still. I think that highlighting
the entire block could be useful. Though I suppose it might be
too noisy and distract from what matters? Alternatively, you'd
need different levels of indentation to capture nested
indentation. That shouldn't be a problem if people are limiting
their indentation levels though...

Regards,


-- 
Brandon McCaig  
Castopulence Software 
Blog 
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'



signature.asc
Description: Digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How coding in Python is bad for you

2017-01-26 Thread Brandon McCaig
On Tue, Jan 24, 2017 at 07:50:20PM +, Ben Bacarisse wrote:
> I suspect that part of the reason these errors occur is
> precisely because they don't matter to the interpreter and
> students are doing a lot of self-easement based on "does it
> work?" tests. 

I cringe when I hear "it works"! In particular, because it's
often followed by "but I don't know how". I can't even count the
number of times I have reviewed code, spotted something
questionable, approached the author about it, and heard "but it
works!" Well if my analysis is correct it shouldn't so one of us
is obviously wrong. Unfortunately, in my experience, they usually
expect the conversation to be over after "but it works"...

Regards,


-- 
Brandon McCaig  
Castopulence Software 
Blog 
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'



signature.asc
Description: Digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How coding in Python is bad for you

2017-01-26 Thread Brandon McCaig
On Tue, Jan 24, 2017 at 07:54:30PM -0600, Tim Chase wrote:
> The editor I use (vim) doesn't even require me to re-select the range
> to shift it.  Just using
> 
>   >']
> 
> or
> 
>   <']
> 
> will indent/dedent from the cursor to the line where your paste ended.

(O_O) You learn something every day. Thank you.

I have been using Vim and vi for probably close to a decade by
now, but I still have a lot to learn... But nevertheless hate to
go without for even a few seconds.

Regards,


-- 
Brandon McCaig  
Castopulence Software 
Blog 
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'



signature.asc
Description: Digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list