on paper, ... If the former, how do you
> access/import them from the various applications/systems?
> (Python's import rules and restrictions, change control/version
> control)
I have a lib directory in my PYTHONPATH to dump 'em.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
hat
> logfile.write()
>
> This becomes more ugly if multiple withs get nested.
You don't have to nest them. Check out contextlib.ExitStack.
ExitStack is designed to handle situations where you don't always
want to enter some context, or you are entering a large number of
them.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
' ') in text:
> space=\n
>
> rightText = text-space
>
> print(rightText)
Your code resembles Python code, but it isn't close enough for me
to offer reasonable help.
You should figure out how to solve your problem *before* you
start to write code. A paper an
On 2019-01-15, Juris __ wrote:
> Hi!
>
> On 15/01/2019 17:04, Neil Cerutti wrote:
>> On 2019-01-11, shibashib...@gmail.com wrote:
>>> Hello
>>>>
>>>> I'm very new in python. I have a file in the format:
>>>>
>>>>
i = 0
for width in (30, 8, 7, 5): # approximations
item = line[i:i+width]
record.append(item)
i += width
records.append(record)
This leaves them all strings, which in my experience is more
convenient in practice. You can convert as you go if you
want,though it won't look nice and simple any longer.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
#x27;all' will return True anyway.
Neat! I expected that a[0] would be executed in that case,
but it is not.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
On 2018-10-12, Peter J. Holzer wrote:
> Neil Cerutti said:
>> I imagine that if I stuck with Go long enough I'd develop a
>> new coding style that didn't inolve creating useful data
>> types.
>
> I haven't used Go for any real project yet (that may change
on code,
but it still works and I can still maintain it with little
trouble.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
On 2018-10-10, Paul Rubin wrote:
> Neil Cerutti writes:
>> As Stephen said, it's sort of silly not to be aware of those
>> issues going in.
>
> If you're saying ESR messed up by using Python in the first
> place for that program, that's not a great advert f
;t agree with, but I think
> it is worth reading. It is around 300 lines, followed by
> several pages of reader comments.
>
> http://esr.ibiblio.org/?p=8161
Thanks for sharing it.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
roll in result):
> # - THIS LINE IS WHERE I NEED HELP # ( if 2, 3, 4, 6 in list: )
> print("you can roll again")
> else:
> print("you have all 1's and 5's in your result")
Ha! Didn't think I'd get to apply DeMorgan's Law so soon.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
functional languages to introduce new
names for things. You'd consider it wherever you'd consider
assigning something to a new name in Python. In this case, it was
probably just to avoid writing out that square root calculation
twice. Though you could use lambda calculus directly instead,
h unfortunately it doesn't help
when an error occurs, requiring you to put it in a finally block
to ensure it happens.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
g like this is possible. "x", "y" and "result" can be
unecessary.
for ply in range(5):
for com in range(5):
print(ply, com, end='')
if ply == com:
print(" Tie")
else:
print()
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
isplay and
PatternFov? In other words, since you're already using the giant,
Swiss Army sledgehammer of the re module, go ahead and use enough
features to cover your use case.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
d look-ahead or similar inspection of more than the
current item. An alternative is a custom generator or iterator
that provides the window you need.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
they can be
sorted. Are you converting to set and then calling difference?
It may still be more efficient than writing your own loop to take
advantage of the sorted status of the original objects.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
t;on high", we are simply required to
> follow them.
>
> IOWs, "Do as they _say_, not as logic dictates"
The Introduction to Computer Science class I'm taking divided
program design into two categories: Top Down Design, and Object
Oriented Design. It's good, be
mendation, but in 10+ years of using
> the csv module, I've not found any issues in using text/ascii mode
> that were solved by switching to using binary mode.
Binary mode was recommended for Python 2, but not 3, where you
open in text mode but use newline=''.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
import numpy as np
>
> X=np.arange(1, 1, 1) #root variable
np.arange creates an object. The assignment makes X refer to that
object.
> x1=X
X refers to the previous object, and then the assignment makes x1
refer to that same object.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
On 2017-12-11, Neil Cerutti wrote:
> On 2017-12-05, Steve D'Aprano wrote:
>> On Wed, 6 Dec 2017 04:20 am, Jason wrote:
>>> while iterating over two files, which are line-by-line
>>> corresponding. The DictReader skipped ahead many lines
>>> breaking
mber of fields is broken
in the data. In my opinion, it should do a thing that makes it
the simplest to handle the situation for the programmer. This is
in fact usually what happens. When there are more records than
define in the header, you can choose what happens by setting
extrasaction. When some records are missing--it sets them to
None. Except, when all the records are missing, it silently hides
the error with no ability provided to recover it.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
ce 'in' would
>> still be true no matter where the desired string is placed. It would be
>> useful to see some sample data of the old data, and the new data
>
> There is now also a line that starts with:
> PCH_CPU_TEMP:
>
> And I do not want that one.
You'll probably want to include the ':' in the startswith check, in case
someday they also add CPU_TEMP_SOMETHING:.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
anyone agree, or am I crazy?
I've used csv.DictReader for years and never come across this
oddity. Very interesting!
I am with you. Silently discarding blank records hides
information--the current design is unusable if blank records are
of interest. Moreover, what's wrong with a dict ful
ce 'in' would
>> still be true no matter where the desired string is placed. It would be
>> useful to see some sample data of the old data, and the new data
>
> There is now also a line that starts with:
> PCH_CPU_TEMP:
>
> And I do not want that one.
You'll probably want to include the ':' in the startswith check,
in case someday they also add CPU_TEMP_SOMETHING:.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
o much better!
You can import wherever you like--only good style requires you to
put them at the top of your file.
Moreover, snippets could be a library, with each snippet a
function, with the import inside the function. That would keep
the module name out of your global namespace.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
On 2017-10-31, Stefan Ram wrote:
> Neil Cerutti writes:
>>You can use the % operator instead of +, and a generator
>>expression instead of map. It's a pretty small improvement,
>>though.
>
> "Improvement" in what sense?
>
> C:\>python -m time
% ('||'.join(str(s) for s in value_list))
At least... I THINK you can use that generator expression in 2.7.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
as well.
>>
>> http://inform-fiction.org/zmachine/standards/z1point0/sect03.html
>
> not sure how 16 characters can be represented by either ascii
> or zscii in only 8 bytes
Oops! I hastily counted completely wrong. It's 10 bytes in ZSCII
version 2, using a shift-lock.
>> an inefficient coding
>
> I suspect he is using ASCII and storing one value in each byte.
There's also ZSCII, which stores roughly 3 characters every 2
bytes. Since all the digits are in A2, this sequence would take
up 7 bytes in ZSCII as well.
http://inform-fiction.org/zmachine/standards/z1point0/sect03.html
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
On 2017-10-13, Steve D'Aprano wrote:
> On Fri, 13 Oct 2017 11:54 pm, Gregory Ewing wrote:
>
>> Neil Cerutti wrote:
>>> I can tell at a glance if a parameter is expected to be
>>> modifiable just by looking at the function signature.
>>
>> The que
to a function
>> having prototype void f(char *s);
>
> That *ought* to be prevented. That's the whole point.
I'm far less experienced in C, but I threw up my hands and
stopped bothering with const qualifiers in C due to such
headaches. When in Rome, program without const qualifiers in C.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
On 2017-10-11, Gregory Ewing wrote:
> Neil Cerutti wrote:
>> I dig const qualifiers, even though I'm comletely fine with
>> their absence from Python.
>
> Out of curiosity, do you have any insights into why you like
> them in C++, if you don't miss them in Py
+ is easy to overcomplicate with the multiple
inheritance feature. Alternatives are almost always preferable.
Some people also appreciate C++'s improvements upon C's type
sytem enough to compile all their C programs with C++. I dig
const qualifiers, even though I'm comletely fine wit
thinking about and
asking questions about Python has been of great interest to me,
and provided entertainment and enlightenment.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
job using a pivot table in Excel.
Office manager, learn thy Excel!
On the other hand, I think Python's csv module is a killer app,
so I do recommend taking the opportunity to learn csv.DictReader
and csv.DictWriter for your own enjoyment.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
insist they understand the iterator protocol and exception
handling first they're bound to think iteration is a hovercraft
full of eels.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
of them are good at explaining what they
know in a comprehensible and entertaining way. I believe you will
benefit from and even enjoy some of the literature. Here's a
recent favorite: "The Pragmatic Programmer", Andrew Hunt and
David Thomas. ISBN-13: 978-0201616224
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
o configure your
email server--it isn't that he or she *can't* do it...
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
east on one
side of the pipeline. Some experience in the industry you want to
script for will really be required, even in such simple cases.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
ython's argument
passing for non-Python programmers strikes me as a sincere effort
to to simplify something that just isn't simple. If calling it,
"pass by assignment," is admitting defeat, then so be it.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
33) / 2
You could also calculate it with a combination of sum and range
builtins, as others have hinted, and if it's homework that's
probably a good idea.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
s separate
API's that allow you to regard those bytes as either plain old
bytes, or as a sequence of runes (not-necessarily normalized
codepoints). If your bytes strings aren't in UTF-8, then Go Away.
https://blog.golang.org/strings
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
ect that has the methods that should only be
> called for active connections. That way it's not possible to do
> things out of sequence.
It's like a bidirectional iterator in C++, except in reverse it's
random access. An iterator that can't easily be modeled with a
generato
nd illuminate dark corners
of both my own skill and Python's features.
An Excel spreadsheet that represents a table of data is fairly
simple to map onto a Python dict. One nearly codeless way is to
export it from Excel as a csv file and then read it with
csv.DictReader.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
this point, after only one bad experience trying to
work around my choice of container.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
at the
> module, connection and cursor levels.
You get autocommit with sqlite3 by setting isolation_level=None
on the connection object.
https://docs.python.org/2/library/sqlite3.html#sqlite3-controlling-transactions
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
On 2017-06-02, Dennis Lee Bieber wrote:
>
> A bit of a long free-association rambling...
>
> On Fri, 2 Jun 2017 12:07:45 + (UTC), Neil Cerutti
> declaimed the following:
>>You're probably not expected to interleave transaction control
>>commands from
ands from different levels of abstraction, e.g., only call
'commit' directly if you called 'begin' directly.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
that
concentrates on functional programming with immutable state if
you haven't done it before. The book that worked for me was
Simply Scheme https://people.eecs.berkeley.edu/~bh/ss-toc2.html,
but that's sorta ancient history now and I'm sure there's lots
more options out there.
--
On 2017-04-03, Jay Braun wrote:
> I hear people say it like the plural of "panda", and others as
> "panduss". Is there a correct way?
I think it is pronounced like the regular word. The second a is
schwa in both the singular and plural.
--
Neil Cerutti
--
https
mn-names portion of an INSERT statement.
quoted_val, = c.execute("SELECT quote(?);", (val,)).fetchone()
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
>> used.
>
> I use it a lot ;-)
Me too. I wrote a script once to convert all my .cfg files to
JSON at one point while trying out a switch from Python to Go,
but never made the changeover.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
in Python (code snippet
D0DE4716-B6E6-4161-9219-2903BF8F547F) to compare names of students (it
worked, but turned out to not be what I needed), but you may also be
able to use some items "off the shelf" from Python's difflib.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
eone asking a great
mathematician "But how do you KNOW that 2 + 2 is 4? Where's it written
down?"... all he can say is "It is".
But it *can* be interesting to try and do otherwise.
http://en.wikipedia.org/wiki/Principia_Mathematica
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
ame package. So since I'm currently working for a
US company I have to consciously remind myself to use their abominations ;)
Yes, we must not allow unmetred errour to paralyse communication.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
y Voltage
code:AIN2
value:0.061256
It's simple to hook into ConfigParser to get whatever meaning you'd
like, and whatever verification you'd find necessary.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
On 8/27/2014 9:40 AM, Jake wrote:
Jake
I disagree!
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
just imagining the
next time I have to do it.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
nd Windows-like modes
to help with the transitional phases.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
editors were invented.
I use and recommend gvim (press > in select mode using the standard
python plugin), but there are plenty of options out there.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
le to use). But I contend you do
need to be a Medieval Scholar to compile and link it. My mind boggles
watching a ./configure vomit ASCII all over my screen. I have to avert
my eyes, make a wish, and make install. ;)
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
here had been. ;)
Python developers are filling part of the gap with libraries, e.g.,
numpy and scipy. I could take advantage of numpy by installing Pandas;
I'll learn Pandas long before I resort to C++.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
On 8/12/2014 2:20 PM, Rustom Mody wrote:
On Tuesday, August 12, 2014 11:10:48 PM UTC+5:30, Neil D. Cerutti wrote:
Beginners are particularly poor, in relation to experts, at noticing the
applicability of idea, and at combining ideas together. Breaking things
into component parts has multiple
me teach *myself* better, too.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
On 8/8/2014 2:35 PM, Neil D. Cerutti wrote:
Here's another attempt at context managing:
@contextlib.contextmanager
def release_if_acquired(lock, blocking=True, timeout=-1):
acquired = lock.acquire(blocking, timeout)
if acquired:
yield acquired
lock.re
On 8/8/2014 12:16 PM, Chris Angelico wrote:
On Sat, Aug 9, 2014 at 2:05 AM, Neil D. Cerutti wrote:
Perhaps defer release, a la a common Go pattern:
with contextlib.ExitStack() as stack:
acquired = lock.acquire(blocking=False)
if acquired:
stack.callback(lock.release
ack.callback(lock.release)
do_stuff
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
ax required for usage.
Classes can be constructed dynamically using metaclasses.
Some of these things can be emulated using just functions and
mappings--it's what C programmers do--but most of classes in Python can
do requires language support.
--
Neil Cerutti
--
https://mail.python.o
you'd have
to explicitly retrieve street_address[0] and ignore the rest.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
ability to display most special
characters correctly (slrn could only do as well the cmd.exe), and have
switched to Thunderbird.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
I could fix my
program(s) the instant I knew which encodings to use. It would have been
much harder to get right using Python2.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
t's where they're described in
Python's docs.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
providing some other
means of exit, e.g., an 'exit' command.
But maybe that's just the shell.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
to get cute).
Of course everybody has to eventually learn about the special syntax
usable in function definitions and function calls.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
lus Rufus Xavier Sasparilla disagrees with it.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
ry less manageable that the ones I
> used in Python ...
C could provide more friendly general purpose containers in its
library, but doesn't. There are some good free ones: glib, for
example.
Cython provides a really nice in-between level.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
mbined with duck typing and simple distribution
of applications is a draw. Go's tools are pretty awesome, and are
scheduled for improvements.
If you can get by with its built in types (or simple aggregates
of them) it feels quite expressive.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
read the class variable. If you
assign to self.x you'll create a new instance variable that hides
the class variable.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
let you, gulp, add more.
Well, that or lisp's designers severely underestimated how much
we like to use our programming languages as non-RPN calculators.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
riables in the local symbol table of
the called function.
Am I oversimplifying?
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
enough features to
bother with its implemention.
Check out Go's switch statement for an example of what it might
look like in Python. Except you'd get it without labeled break or
the fallthrough statement. Would you still want to use it?
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
a followup to
that mind-bending experience.
http://www.eecs.berkeley.edu/~bh/ss-toc2.html
I wouldn't recommend trying to learn anything at the same time as
learning Haskell. ;)
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
<' and key[-1] == '>'"
> Traceback (most recent call last):
> File "P:\Python34\lib\timeit.py", line 292, in main
> x = t.timeit(number)
> File "P:\Python34\lib\timeit.py", line 178, in timeit
> timing = self.inner(it, self.timer)
> File "", line 6, in inner
> key[0] == '<' and key[-1] == '>'
> IndexError: string index out of range
The corrected version
key and key[0] == '<' and key[-1] == '>'
probably still wins the Pretty Unimportant Olympics.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
ll catch that with your unit tests ;)
It's easy to forget exactly why startswith and endswith even exist.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
the fastest after all?
I think the following would occur to someone first:
if key[0] == '<' and key[-1] == '>':
...
It is wrong to avoid the obvious. Needlessly ornate or clever
code will only irritate the person who has to read it later; most
likely yourself.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
.
There will be an exception only if it is zero-length. But good
point! That's a pretty sneaky way to avoid checking for a
zero-length string. Is it a popular idiom?
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
ust the beginning, but it's a pretty good place.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
DOS, Windows, and Linux
> computers for years:
>
> disable the caps-lock key
I really liked rebinding it to Left-CTRL. I only stopped doing
that because it screwed up my work flow when not at a keyboard I
could remap.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
is few controversial opinions
brought into other topics. Tim's post was responding to a
specific, well-presented criticism of Python's string
implementation. Left unchallenged, it might linger unhappily in
the air, like a symphony ended on a dominant 7th chord.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
On 2014-02-06, Tim Chase wrote:
> On 2014-02-06 17:40, Mark Lawrence wrote:
>> On 06/02/2014 14:02, Neil Cerutti wrote:
>> >
>> > You must open the file in binary mode, as that is what the csv
>> > module expects in Python 2.7. newline handling can be enscrewe
in Python 2.7. newline handling can be enscrewed
if you forget.
file = open('raw.csv', 'b')
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
answer to test your program's answer with.
2. A general idea of how to solve the problem.
It's often a mistake to start writing code. Eventually you'll be
able to go directly from problem to code more often, but it will
take practice.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
case was wanting to print a timedelta without
> the fractions of seconds. The most straight-forward is:
>
> print td.replace(microseconds=0)
That would be nice.
In the meantime, this works for your use case:
td -= td % timedelta(seconds=1)
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
ely, just like the responsible adults that we are. Isn't
that right, Mr... Poopy-Pants?
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
maybe I'm just naive.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
On 2014-01-22, wxjmfa...@gmail.com wrote:
> In fact, Python just becomes the last tool I (would)
> recommend, especially for non-ascii users.
Have a care, jmf. People unfamiliar with your opinions might take
that seriously.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/
m, how
> can judge the OP's reaction to it?
Obvious copying of another person's program, nearly verbatim, is
most likely to be detected. Well, that and submitting one of the
entrapment-purposed answers that are sometimes made availalbe
here and elsewhere.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
On 2014-01-20, Devin Jeanpierre wrote:
> On Mon, Jan 20, 2014 at 8:16 AM, Mark Lawrence
> wrote:
>> On 20/01/2014 16:04, Neil Cerutti wrote:
>>> I use regular expressions regularly, for example, when
>>> editing text with gvim. But when I want to use them in Python
ssions regularly, for example, when editing
text with gvim. But when I want to use them in Python I have to
contend with the re module. I've never become comfortable with
it.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list
1 - 100 of 1213 matches
Mail list logo