you're
working in bytes or text (str). Keep the division clean, that way all
you other code can be written appropriately. So: the command pipe output
is bytes. COnvert it to text before passing to your text parsing code.
That way all the parsing code can work in text (str) and have no we
, and the output from your programme
- a complete transcript of any error message, for example if your
programme raised an exception
Make sure these are inline in your message, _not_ attachments. We drop
attachments in this list.
Cheers,
Cameron Simpson
_
MAC, value the name). Return the dictionary.
If the dictionary is empty, there were no devices.
Not that like almost all collections, empty dictionaries are "false", so
you can go:
bluetooth_devices = scanner.bluetooth_scan()
if not bluetooth_devices:
... no devices found ...
C
())
File "/home/srinivasan/Downloads/bt_tests/qa/test_library/Bt.py",
line 74, in bluetooth_scan
print("the value", res[1])
IndexError: list index out of range
Well, you've printed your list:
['Scanning ...']
It is a single
f range characters -- ordinals >= 256 -- in a "byte"
string).
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
oosely speaking, safe:
thread1:
print(sorted(object))
thread2:
print(sorted(object,reverse=True))
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/m
t, not it cannot be current.)
But first, fine out what's wrong. Try the type test I suggest and see
how far you get.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
ext pattern exercise which I always
have struggled with. Last language I did this in was Perl and had all
sorts of headaches. ๐ Python seems cleaner from the reading I have
done thus far. Lets see what challenges wait in front of me.
I used to use Perl extensively. I put off moving to Python for
sability: the above code complains about
each issue it encounters, and finally quits with an additional message.
In a real programme that addition message would include a "usage"
message which describes the expected arguments.
Cheers,
Cameron Simpson
On 27Jan2019 10:30, Peter Otten <__pete...@web.de> wrote:
Cameron Simpson wrote:
Mats has mentioned the modules getopt and argparse etc. These are
primarily aimed at option parsing ("-v", "-o foo"). Your situation
occurs _after_ the option parsing (in your case, th
iced).
Does this clarify things for you?
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
On 24Feb2019 14:30, boB Stepp wrote:
On Sun, Feb 24, 2019 at 1:39 AM Cameron Simpson wrote:
It looks like the resizeterm() function updates the curses _internal_
records of what it believes the physcial terminal size to be. When you
physically resize a terminal the processes within it
notices changes
automatically then it is uncommon to need to call resizeterm().
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
s_term_resized, resizeterm and the "internal" resize_term
functions are recent additions :-) From "man 3 resizeterm":
This extension of ncurses was introduced in mid-1995. It was
adopted in NetBSD curses (2001) and PDCurses (2003).
Cheers,
Cameron Simpson
eFilm(name, platform, dateAdded, tpe):
return Film(name, platform, dateAdded)
Unless there's more stuff happening in these functions which you've
stripped out for clarity you could just call the object constructors
directly from the if statements:
if data['tpe'] == 'Game':
a = Game(name, platform, dateAdded)
game = {a: tpe}
media.append(game)
Why would I only get one object in media, even though all three are
created?
As you may gather, all three input lines are processed, but only one
gets turned into an object to add to media. Change the if/if into an
if/elif/else and see if things become more obvious.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
ust the one from the int()
call, so it needn't indicate bad user input, it could as easily indicate
some subsequent bug in your code, as many functions can raise ValueError
if they are handed something unsatisfactory.
Cheers,
Cameron Simpson
___
er on the screen is changed to
the new background rendition.
ยท Wherever the former background character appears, it is changed
to the new background character.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
quot;) contains only the library, not header files or
doco wanted for development.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
and learn...
The octothorpe is only a comment marker at the start of a word.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
ou tell me what kind of system you have?
For variety, in my own code I keep the tests for foo.py in foo_tests.py,
the better to be seen next to foo.py in listings and file completion.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To u
lues:
would be accepted. Which may be ok, and it should certainly be ok for
your first attempt: tighten things up later.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
tartswith('/'):
raise ValueError("must be an absolute path")
with open(input_file, 'rb') as f:
return io.BytesIO(f.read())
Because of the Pfx the ValueError gets the input_file value in question
prefixed automatically, so you don
as defined: the
scope at the bottom of your programme.
This is called a "closure": functions has access to the scope they are
define in for identifiers not locally defined (eg in the parameters or
the function local variables - which are those assigned to in the code).
This means you
nested
functions, but did not know it worked for lambdas as well.
Lambda are functions. Same rules.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
roup(1,2,3,4)
year = int(year)
month = int(month)
day = int(day)
# turn this into a datetime.date object
date = datetime.date(year, month, day)
and return the computed date. Then just keep this in the for loop so it
is obvious what's going
quot;Using Django" list there.
There's a guideline to posting here:
https://code.djangoproject.com/wiki/UsingTheMailingList
but your post looks fairly good on the face of it.
Hoping this helps,
Cameron Simpson
Objective : display main page with multiple links to other pages. Use
j
=0, /)
Return the sum of a 'start' value (default: 0) plus an iterable of numbers
When the iterable is empty, return the start value.
This function is intended specifically for use with numeric values and
may reject non-numeric types.
Cheers,
Cameron Simpson
__
foo = Foo()
print("age =", foo.age)
@property arranges this using descriptors: in the example above it
arranges that the class "age" attribute is a descriptor with a __get__
method.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
aged install and just do
it all from scratch.
I suspect this has something to do with me interrupting the install process,
because I interrupted it precisely when it was fetching the package that it
can't find now.
Let me know if I should be asking this elsewhere.
Thi
simply
the row from the CSV data as a first cut).
The nice thing about a namedtuple is that the values are available as
attributes: you can use "key.flavour" etc to inspect the tuple.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
_date[date] += 1
A defaultdict is a dict which magicly makes missing elements when they
get access, using a factory function you supply. Here we're using "int"
as that factory, as int() returns zero.
I presume you've got the timestamp => date conversion
The biggest change you'll find coming from Java is likely the typing:
Python _values_ are strongly typed, but the variables are not - they can
refer to a value of any type. And there aren't really Java interfaces.
However, there are lint tools to look for issues like this.
Oh yes:
se cut/paste is very
fast (iTerm3 has a mode like most X11 apps: select implicitly copies, so
no Cmd-C copy keystroke for me either).
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
dy of
the message.
Googling has not helped me to find a solution [...]
1: I recommend duckduckgo instead of Google for privacy/tracking
reasons.
2: When I search, I tend to find people with the same problem, not
necessarily people with answers. But this question might be hard to get
(look it
up). But a since pass over the list isn't enough to sort the whole
thing.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
//github.com/threatstack/libmagic
3: https://pypi.org/project/python-magic/
4: https://pypi.org/search/?q=magic
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
in
a local file.
It is hard to be any more specific without knowing what you consider a
task, and how you'd check if it was active.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Windows dropins for this facility. Maybe install this package:
https://pypi.org/project/pyreadline-ais/
maybe with "python -m pip install pyreadline-ais".
Then use it according to the documentation for the stdlib readline
module:
https://docs.python.org/3/library/readline.html#mo
't yours. There should be a Windows equivalent for probing a
process.
The converse part where you start the process includes this:
P = subprocess.Popen(.) # start the program
with open(pid_filename, 'w') as pidf:
print(P.pid, file=pidf)
to update the process id fi
if m:
category = m.match(1)
id_number = m.match(2)
recipient = m.match(3)
else:
m = re.match(...)
... more tests here ...
...
...
else:
... report unmatched line for further consideration ...
3: You use ".*" a lot. This is quite prone to matching too much. You
might find things like "\S+" better, which matches a single
nonwhitespace "word". It depends a bit on your input.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
his list drops attachments). That we we can all run
exactly the same code, and solve your actual problem.
And start always using:
from __future__ import print_function
in Python if you're using print. That will make your prints behave the
same regardless if whether they are using Python 2 or 3.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
e of the other
Pis? Though given "Network is unreachable" I'd guess no packets get sent
at all.
I repeat my disclaimer: I've not used an ad hoc wifi network.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
:
words = text.split()
for i in enumerate(words):
Word = ' '.join(words[:i])
print (word)
answer = input('Keep word (ynq)?')
if answer == 'n':
continue
elif answer = 'q':
break
for i, v in enumerate(description):
if word in description[i]:
description.pop[i]
The inner for loop still has all the same issues as before. The outer
loop is now more robust because you've iterating over the copy.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
ly true. In the extreme case you just treat the
first loop specially:
first = True
while first or the-actual-condition:
... do stuff ...
first = False
if you want to use "first" during the "do stuff". Or you could be a bit
more reliable and go:
first_test = True
at this point.
He has, as it happens, over in fl...@python.org.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
ly depending on what data structure is
used to arrange the data, because some actions are cheap in some
structures and expensive in others, so you choose the efficient action
where possible.
Cheers,
Cameron Simpson
___
Tutor maillist - Tut
you'd need an SQLite library for PHP, but I cannot
believe that one does not exist. (Or you could also write your web
application in Python instead of PHP.)
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or chan
ing to Flask and the environment: because a Flask app is often
invoked from within a web server instead of directly, it isn't feasible
to pass it "command line" arguments to control it. So the environment
becomes the most convenient place for ad hoc special settings.
Cheers,
Cameron
as found.
To turn all this into a subscriptable list, define the __getitem__
method as a function accepting an index. If that index is an int, just
return that element. If the index is a slice (start:stop:stride), call
the more complicated function to return multiple elements.
does one write a one element tuple? Like this:
(9,)
Here the trailing comma is _required_ to syntacticly indicate that we
intend a 1 element tuple instead of a plain "9 in parentheses") as in
the earlier assignment statement.
I'm not sure an
your initialiser cannot complete correctly.
Consider:
x = Foo()
After this assignment we expect "x" to be a usable instance of Foo. We
don't put special checks; what would such checks look like? (There are
some answers for that, but they're all poor.)
uot;py" command (I'm not on Windows here). So it may be that when
you issue the command "python" it isn't running the Python interpreter
but something else.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
r would not have a callable to work with; it would get the None
that your @collect returns.
This is the other argument for always returning a callable: to
interoperate with other decorators, or of course anything else which
works with a callable.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
ven your description.
Unless they're snapshots/samples, in which case "Telemetric" ?-)
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
re precise than
loose verbal descriptions alone).
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
message.
If you move your misplaced "return to_ints(nums), to_ints(nums2)"
statement up into the get_numbers function you should be better off,
because then it will return a list of numbers, not strings.
Cheers,
Cameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
x27;m getting an area function from a nicely named class. (Also, I
wouldn't have to import the area function explicitly - it comes along
with the class nicely.)
So the static method is used to associate it with the class it supports,
for use when the caller doesn't have an instance to
On 14Aug2019 11:15, Steven D'Aprano wrote:
On Wed, Aug 14, 2019 at 09:58:35AM +1000, Cameron Simpson wrote:
On 11Aug2019 22:58, James Hartley wrote:
>I am lacking in understanding of the @staticmethod property.
>Explanation(s)/links might be helpful. I have not found the descript
ting out that they should not
I think you're not using "nesting" the way I think of it. Can you
provide an example bit of code illustrating what you're thinking of and
explaining your concerns? Also, your paragraph looks a little truncated.
e: int) -> list:
return ( lst[x:x+size] for x in range(0, len(lst), size) )
Omitting the square brackets turns this into a generator expression. It
returns an iterator instead of a list, which functions like the
generator function I sketched, and generates the c
301 - 360 of 360 matches
Mail list logo