[Tutor] beginner question

2011-11-01 Thread Mayo Adams
When writing a simple for loop like so:

 for x in f

where f is the name of a file object, how does Python "know" to interpret
the variable x as a line of text, rather than,say, an individual character
in the file? Does it automatically
treat text files as sequences of lines?

-- 
Mayo Adams


287 Erwin Rd.
Chapel Hill, NC 27514
(919)-968-7889
mayoad...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Writing processed text to another file(beginner)

2011-11-05 Thread Mayo Adams
Code to build a list z to contain all the first words in each line of a
text file:

z=[]

f=open('C:/atextfile.txt')

for aLine in f:

str=aLine

a=str.split()

z.append(a)


I would like to work further with the list z once the file has been
stripped, and the list is complete but am so clueless about Python and its
curlybracelessness that I don't know when the for loop terminates.
Obviously I don't want to write to the file after every line is read.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] write list of tuples to file (beginner)

2011-11-22 Thread Mayo Adams
I have a list of tuples of the form (string,integer) that I would like to
write  to  a file with a line break between each. Simply writing to a file
object thus

for item in tuplelist
   outputfile.write (item)

doesn't work, and I suppose I scarcely expect it should, but I am at a loss
to find out how to do it.

-- 
Mayo Adams



mayoad...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] pass tuples to user defined function(beginner)

2011-11-28 Thread Mayo Adams
I am trying to pass a set of tuple strings from a file to a function I
have defined.  Each tuple is on a separate line, and looks something
like this:
 ('note',2048)
The function has two parameters , and is defined thus: def
findindex(dval,ticks):
Apparently, I need to cast the second value as an integer in the body
of the function in order to work with it as such, but when I attempt
int(ticks) I get
ValueError: invalid literal for int() with base 10: '2048)'

Upon searching for elucidation of this on the internet I find nothing
but esoterica, at least as far as I am concerned.
Any pointers would make me happy.

--
Mayo Adams



mayoad...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pass tuples to user defined function(beginner)

2011-11-29 Thread Mayo Adams
Apologies for my numerous offenses to protocol, and gratitude for  the
suggestions all around.And yet...  as to the notion of a tuple
existing in some non-Platonic sense, I suspect I will have carry my
confusion away in order to dispel it by further reading.
"Wrong on both counts?" Hey, you win! I WAS wrong. But if it is not a
tuple that is in the file, it would be helpful to know what it is.
Presumably, a string representing a tuple. And as to the matter of
representation,  I cant immediately see how anything in a script is
anything other than a representation of some kind, hence the
distinction between representamen and object does no work for me.

Yes, I should have been clearer as to what I was trying to achieve,
but I underestimated the good will of this community(in most cases)and
their willingness to help.  For which, as I said, much thanks.

On Tue, Nov 29, 2011 at 8:02 AM, Steven D'Aprano  wrote:
> Peter Otten wrote:
>
>> And here's the lazy-bastard version:
>
> [...]
>>
>> ...     print ast.literal_eval(line.strip())
>
> Nice!
>
>
> --
> Steven
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Mayo Adams


287 Erwin Rd.
Chapel Hill, NC 27514
(919)-968-7889
mayoad...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PLEASE HELP

2018-04-13 Thread Mayo Adams
 discrete, not discreet.

On Fri, Apr 13, 2018 at 11:38 AM, Neil Cerutti  wrote:

> On 2018-04-13, David Rock  wrote:
> >
> >> On Apr 13, 2018, at 09:24, Neil Cerutti  wrote:
> >>
> >> On 2018-04-12, Scharrer, Brianna  wrote:
> >>> Applications of basic language syntax
> >>>
> >>> Date/time string parsing
> >>>
> >>> Time stamps on data are often recorded in the standard ISO date
> >>> and time format as shown below
> >>> 1999-02-14T21:02:37 > 9:02pm on February 14, 1999
> >>>
> >>> Write code that when given a datetime string and outputs a
> >>> human readable version exactly in the format specified below.
> >>
> >> I disagree that the first version isn't human readable. It is
> >> both human readable and stores the date/time in lexicographic
> >> order, which is extremly useful for both humans and machines.
> >
> > Don???t nitpick the definition of ???human readable;??? it
> > isn???t relevant to the assignment and just serves to confuse
> > the student.  Using the phrase ???human readable??? is just a
> > poor choice for describing the assignment parameters: changing
> > from one format to another (ISO -> ???standard English??? (for
> > lack of a better description of the target format).  That???s
> > the only thing that matters in this context.
>
> It is relevant to the assignment if the student hadn't noticed
> that the date was human readable. I was hoping to correct this
> possible misapprehension resulting from the poor assignment
> language.
>
> --
> Neil Cerutti
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Mayo Adams

287 Erwin Rd.
Chapel Hill, NC 27514
(919)-780-3917
mayoad...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Environment variables and Flask

2019-06-27 Thread Mayo Adams
I have for some time been flummoxed as to the significance of setting
environment variables, for example in order to run a Flask application.
What are these environment variables, exactly, and why is it necessary to
set them? "Googling" here simply leads me into more arcana, and doesn't
really help.

-- 
Mayo Adams
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Environment variables and Flask

2019-06-28 Thread Mayo Adams
Many thanks to some very bright and helpful gentlemen.

On Fri, Jun 28, 2019 at 9:24 AM Mats Wichmann  wrote:

> On 6/27/19 11:24 PM, Mayo Adams wrote:
> > I have for some time been flummoxed as to the significance of setting
> > environment variables, for example in order to run a Flask application.
> > What are these environment variables, exactly, and why is it necessary to
> > set them? "Googling" here simply leads me into more arcana, and doesn't
> > really help.
>
> As others have noted, it's a way to pass information from one process to
> another at startup time.   Since this is a Python list, I thought it
> might be instructive to show how it works. In Python, you access these
> environment variables through a dictionary in the os module, called
> environ, which "survives" across the call-another-process boundary,
> unlike any normal variables you might set in your program. Here's a
> trivial Python app that is able to recognize those environment variables
> that begin with MYENV_.  That points up one issue with environment
> variables right away: it's a namespace you share with everybody, and
> there's a chance someone accidentally is using a variable you think is
> important - because it's important to them in their context, not yours.
> So tricks like special naming conventions may be useful.
>
> In this snip, we build a dictionary from os.environ, using only the keys
> that seem to be "for us":
>
>
> === child.py ===
> import os
>
> myenv = { k: v for k, v in os.environ.items() if "MYENV_" in k }
>
> print("child found these settings:", myenv)
> ==
>
> Now write another script which sets a value, then calls the child
> script; then sets a different value, then calls the child script.
>
> === parent.py ===
> import os
> import subprocess
>
> print("Calling with MYENV_foo set")
> os.environ['MYENV_foo'] = "Yes"
> subprocess.run(["python", "child.py"])
>
> print("Calling with MYENV_bar set")
> os.environ['MYENV_bar'] = "1"
> subprocess.run(["python", "child.py"])
> ==
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


-- 
Mayo Adams

287 Erwin Rd.
Chapel Hill, NC 27514
(919)-780-3917
mayoad...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor