Re: Multiplication

2024-04-01 Thread Joel Goldstick via Python-list
On Mon, Apr 1, 2024 at 1:26 PM Piergiorgio Sartor via Python-list
 wrote:
>
> On 01/04/2024 10.40, Stefan Ram wrote:
> >  Q: How can I multiply two variables in Python? I tried:
> >
> > a = 2
> > b = 3
> > print( ab )
> >
> >  but it did not work.
> >
> >  A: No, this cannot work. To multiply, you need the multiplication
> >  operator. You can import the multiplication operator from "math":
> >
> >  Code example:
> >
> > from math import *
> >
> > a = 2
> > b = 3
> > print( a * b )
>
> I guess the operator "*" can be imported from any module... :-)
>
> bye,
>
> --
>
> piergiorgio
>
> --
> https://mail.python.org/mailman/listinfo/python-list

>>> a = 3
>>> b = 5
>>> print(a*b)
15
>>>


No import is necessary.


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


Re: ModuleNotFoundError

2022-06-17 Thread Joel Goldstick
On Fri, Jun 17, 2022 at 8:31 AM inhahe  wrote:
>
> sorry, I may have misused the term "namespace." I'm not sure what the
> proper word is for the names currently loaded into the global scope.
>
> On Fri, Jun 17, 2022 at 8:26 AM inhahe  wrote:
>
> > sys is a built-in module, but it's not in the namespace unless you import
> > it first.
> > before your print statement, enter "import sys"
> >
> > On Fri, Jun 17, 2022 at 8:23 AM  wrote:
> >
> >> Thank you for your email.
> >>
> >> C:\Users\zszen>python.exe
> >> Python 3.10.5 (tags/v3.10.5:f377153, Jun  6 2022, 16:14:13) [MSC v.1929
> >> 64 bit (AMD64)] on win32
> >> Type "help", "copyright", "credits" or "license" for more information.
> >> >>> print(sys.version)
> >> Traceback (most recent call last):
> >>   File "", line 1, in 
> >> NameError: name 'sys' is not defined
> >>
> >> >>> print(sys.executable)
> >> Traceback (most recent call last):
> >>   File "", line 1, in 
> >> NameError: name 'sys' is not defined
> >>
> >> On Fri, Jun 17, 2022, at 12:35 PM, Eryk Sun wrote:
> >> > On 6/17/22, Zoltan Szenderak  wrote:
> >> > >
> >> > > print(sys.version_info) and executable:
> >> > > Unable to initialize device PRN
> >> >
> >> > That's the command-line "print" program. You need to first start the
> >> > Python shell via python.exe. The prompt should change to ">>> ". Then
> >> > run print(sys.version) and print(sys.executable).
> >> >
> >> --
> >> https://mail.python.org/mailman/listinfo/python-list
> >>
> >
> --
> https://mail.python.org/mailman/listinfo/python-list

sys is a module that is part of 'batteries included' in python.  Since
it is not part of the language per se, you need to import it


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


Re: How to replace characters in a string?

2022-06-08 Thread Joel Goldstick
On Wed, Jun 8, 2022 at 5:22 AM Karsten Hilbert  wrote:
>
> Am Wed, Jun 08, 2022 at 11:09:05AM +0200 schrieb Dave:
>
> > myString = 'Hello'
> > myNewstring = myString.replace(myString,'e','a’)
>
> That won't work (last quote) but apart from that:
>
> myNewstring = myString.replace('e', 'a')
>
> Karsten
> --
> GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B
> --
> https://mail.python.org/mailman/listinfo/python-list


Sorry if I'm not reading the nuances correctly, but it looks to me
that you failed to realize that string methods return results.  They
don't change the string in place:

Python 3.8.10 (default, Mar 15 2022, 12:22:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> str1 = "\u2019string with starting smart quote"
>>> str1
'’string with starting smart quote'
>>> new_str = str1.replace("\u2019","'")
>>> str1
'’string with starting smart quote'
>>> new_str
"'string with starting smart quote"
>>> repr(str1)
"'’string with starting smart quote'"
>>> repr(new_str)
'"\'string with starting smart quote"'
>>>

As you can see, str1 doesn't change, but when you 'replace' on it, the
result you want is returned to new_str

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


Re: Comparing sequences with range objects

2022-04-07 Thread Joel Goldstick
On Thu, Apr 7, 2022 at 7:19 AM Antoon Pardon  wrote:
>
> I am working with a list of data from which I have to weed out duplicates.
> At the moment I keep for each entry a container with the other entries
> that are still possible duplicates.
>
> The problem is sometimes that is all the rest. I thought to use a range
> object for these cases. Unfortunatly I sometimes want to sort things
> and a range object is not comparable with a list or a tuple.
>
> So I have a list of items where each item is itself a list or range object.
> I of course could sort this by using list as a key function but that
> would defeat the purpose of using range objects for these cases.
>
> So what would be a relatively easy way to get the same result without wasting
> too much memory on entries that haven't any weeding done on them.
>
> --
> Antoon Pardon.
> --
> https://mail.python.org/mailman/listinfo/python-list

I'm not sure I understand what you are trying to do, but if your data
has no order, you can use set to remove the duplicates

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


Re: All permutations from 2 lists

2022-03-02 Thread Joel Goldstick
On Wed, Mar 2, 2022 at 5:07 PM Larry Martell  wrote:
>
> On Wed, Mar 2, 2022 at 5:00 PM Cameron Simpson  wrote:
> >
> > On 02Mar2022 08:29, Larry Martell  wrote:
> > >On Tue, Mar 1, 2022 at 7:32 PM Rob Cliffe  
> > >wrote:
> > >> I think itertools.product is what you need.
> > >> Example program:
> > >>
> > >> import itertools
> > >> opsys = ["Linux","Windows"]
> > >> region = ["us-east-1", "us-east-2"]
> > >> print(list(itertools.product(opsys, region)))
> > >
> > >This does not work if region = []. I wrote in question that either
> > >list could be empty.
> >
> > What do you want to get if a list is empty? You haven't said. My
> > personal expectation would be an empty result.
> >
> > Alternatively, if you expect an empty list to imply some single default
> > the the experession:
> >
> > the_list or (the_default,)
> >
> > might be of use.
>
> I've solved the issue.
> --
> https://mail.python.org/mailman/listinfo/python-list

Would you be so kind as to show the results of your solution?

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


Re: All permutations from 2 lists

2022-03-02 Thread Joel Goldstick
On Wed, Mar 2, 2022 at 9:01 AM Larry Martell  wrote:
>
> On Wed, Mar 2, 2022 at 8:54 AM Joel Goldstick  
> wrote:
> >
> > On Wed, Mar 2, 2022 at 8:46 AM Larry Martell  
> > wrote:
> > >
> > > On Wed, Mar 2, 2022 at 8:37 AM Antoon Pardon  wrote:
> > > >
> > > >
> > > > Op 2/03/2022 om 14:27 schreef Larry Martell:
> > > > > On Tue, Mar 1, 2022 at 7:21 PM<2qdxy4rzwzuui...@potatochowder.com>  
> > > > > wrote:
> > > > >> On 2022-03-01 at 19:12:10 -0500,
> > > > >> Larry Martell  wrote:
> > > > >>
> > > > >>> If I have 2 lists, e.g.:
> > > > >>>
> > > > >>> os = ["Linux","Windows"]
> > > > >>> region = ["us-east-1", "us-east-2"]
> > > > >>>
> > > > >>> How can I get a list of tuples with all possible permutations?
> > > > >>>
> > > > >>> So for this example I'd want:
> > > > >>>
> > > > >>> [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows",
> > > > >>> "us-east-1"), "Windows", "us-east-2')]
> > > > >>>
> > > > >>> The lists can be different lengths or can be 0 length. Tried a few
> > > > >>> different things with itertools but have not got just what I need.
> > > > >> [(o, r) for o in os for r in region]
> > > > > This does not work if region = []. I wrote in my question that either
> > > > > list could be empty.
> > > >
> > > > What do you mean it doesn't work? The result seems to be an empty list,
> > > > which IMO is a perfectly valid result.
> > > >
> > > > All possible permutations over two collections where one collection is
> > > > empty, should IMO give you an empty collection.
> > >
> > > If one list is empty I want just the other list. What I am doing is
> > > building a list to pass to a mongodb query. If region is empty then I
> > > want to query for just the items in the os list. I guess I can test
> > > for the lists being empty, but I'd like a solution that handles that
> > > as down the road there could be more than just 2 lists.
> > > --
> > > https://mail.python.org/mailman/listinfo/python-list
> >
> > Does this help you out:
> >
> > >>> [(o,r) for o in opsys for r in region or "x"]
> > [('Linux', 'x'), ('Window', 'x')]
>
> That doesn't work if opsys = [] - either list could be empty.

So, maybe what you need to do is determine the length of the longest
list, and pad the other lists as required before producing the tuples?

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


Re: All permutations from 2 lists

2022-03-02 Thread Joel Goldstick
On Wed, Mar 2, 2022 at 8:46 AM Larry Martell  wrote:
>
> On Wed, Mar 2, 2022 at 8:37 AM Antoon Pardon  wrote:
> >
> >
> > Op 2/03/2022 om 14:27 schreef Larry Martell:
> > > On Tue, Mar 1, 2022 at 7:21 PM<2qdxy4rzwzuui...@potatochowder.com>  wrote:
> > >> On 2022-03-01 at 19:12:10 -0500,
> > >> Larry Martell  wrote:
> > >>
> > >>> If I have 2 lists, e.g.:
> > >>>
> > >>> os = ["Linux","Windows"]
> > >>> region = ["us-east-1", "us-east-2"]
> > >>>
> > >>> How can I get a list of tuples with all possible permutations?
> > >>>
> > >>> So for this example I'd want:
> > >>>
> > >>> [("Linux", "us-east-1"), ("Linux", "us-east-2"), ("Windows",
> > >>> "us-east-1"), "Windows", "us-east-2')]
> > >>>
> > >>> The lists can be different lengths or can be 0 length. Tried a few
> > >>> different things with itertools but have not got just what I need.
> > >> [(o, r) for o in os for r in region]
> > > This does not work if region = []. I wrote in my question that either
> > > list could be empty.
> >
> > What do you mean it doesn't work? The result seems to be an empty list,
> > which IMO is a perfectly valid result.
> >
> > All possible permutations over two collections where one collection is
> > empty, should IMO give you an empty collection.
>
> If one list is empty I want just the other list. What I am doing is
> building a list to pass to a mongodb query. If region is empty then I
> want to query for just the items in the os list. I guess I can test
> for the lists being empty, but I'd like a solution that handles that
> as down the road there could be more than just 2 lists.
> --
> https://mail.python.org/mailman/listinfo/python-list

Does this help you out:

>>> [(o,r) for o in opsys for r in region or "x"]
[('Linux', 'x'), ('Window', 'x')]


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


Re: Problem with python

2021-09-04 Thread Joel Goldstick
On Sat, Sep 4, 2021 at 2:29 PM Igor Korot  wrote:
>
> Hi, ALL,
>
> [code]
> igor@WaylandGnome ~/bakefile $ python
> Python 3.9.6 (default, Aug  8 2021, 17:26:32)
> [GCC 10.3.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from distutils import sysconfig
> >>> print sysconfig.get_python_inc()
>   File "", line 1
> print sysconfig.get_python_inc()

 print( sysconfig.get_python_inc())

Since python3 print is a function.
>   ^
> SyntaxError: invalid syntax
> >>>
> [/code]
>
> What is the proper way to fix this?
>
> Thank you.
> --
> https://mail.python.org/mailman/listinfo/python-list



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


Re: Regarding inability of Python Module Winsound to produce beep in decimal frequency

2021-08-15 Thread Joel Goldstick
On Sun, Aug 15, 2021 at 1:03 AM Chris Angelico  wrote:
>
> On Sun, Aug 15, 2021 at 1:02 PM John O'Hagan  wrote:
> >
> > > On 2021-08-13 17:17, Chris Angelico wrote:
> > > > Is it really? In my experience, no human ear can distinguish 277Hz
> > > > from 277.1826Hz when it's played on a one-bit PC speaker, which the
> > > > Beep function will be using.
> >
> > Rounding to integer frequencies will produce disastrously out-of-tune
> > notes in a musical context! Particularly for low notes, where a whole
> > semitone is only a couple of Hz difference. Even for higher notes, when
> > they're played together any inaccuracies are much more apparent.
>
> But before you advocate that too hard, check to see the *real*
> capabilities of a one-bit PC speaker. You go on to give an example
> that uses PyAudio and a sine wave, not the timer chip's "beep"
> functionality.
>
> Try getting some recordings of a half dozen or so computers making a
> beep at 440Hz. Then do some analysis on the recordings and see whether
> they're actually within 1Hz of that.
>
> (And that's aside from the fact that quite a number of computers will
> show up completely silent, due to either not having an internal
> speaker, or not letting you use it.)
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list

This thread got me curious, and I found this article.  The code is
very similar to the pyaudio version a few responses back.
https://thehackerdiary.wordpress.com/2017/06/09/it-is-ridiculously-easy-to-generate-any-audio-signal-using-python/

except it doesn't need pyaudio

I run Ubuntu 20.04, and I had problems getting pyaudio on my machine.

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


Re: Python language packages isn't working in Visual Studio Code

2021-05-03 Thread Joel Goldstick
On Mon, May 3, 2021 at 2:00 PM inhahe  wrote:
>
> I don't think attaching images works on this kind of list. Maybe send a
> link to it..
>
> On Mon, May 3, 2021 at 1:51 PM Osmany Guerra 
> wrote:
>
> > Hi, I have problem with the python interpreter in the Visual Studio Code.
> > It was running ok, but now isn't working. I have downloaded, installed and
> > unistalled several times without having results. How could I fix that?
> > I'm using windows 10 64-bit,  VSCode x64-1.55.2, and Python 3.9.4.
> > I'm sending you a picture of my laptop screen too.
> > Waiting for your reply
> > Regards Osmany
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> --
> https://mail.python.org/mailman/listinfo/python-list

Better yet, cut and paste your relevant text in your email message here

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to loop over a text file (to remove tags and normalize) using Python

2021-03-10 Thread Joel Goldstick
On Tue, Mar 9, 2021 at 10:36 PM S Monzur  wrote:
>
> Thanks! I ended up using beautiful soup to remove the html tags and create
> three lists (titles of article, publications dates, main body) but am still
> facing a problem where the list is not properly storing the main body.
> There is something wrong with my code for that section, and any comment
> would be really helpful!
>

Can you use a very small file to test?  I think you could edit your
data file to contain maybe two or three articles.  Then you could post
that file in your email (no attachments).  And you could post your
code which is probably not very long.  In that way, people here will
be better able to help you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python cannot count apparently

2021-02-07 Thread Joel Goldstick
On Sun, Feb 7, 2021 at 2:36 PM Philipp Daher via Python-list
 wrote:
>
> Hello,
>
> I recently coded this snippet of code:
> myString=„hello“
> for i in range(len(myString):
>  print(string[i])
>
> And now for the weird part:
>
> SOMETIMES, the output is this:
>
> hello
>
> And SOMETIMES, the output changes to:
>
> ohell
>
> WHY??? Why do I get different outputs with the EXACT SAME CODE?
>
> Can someone help me please? Thank you
> --
> https://mail.python.org/mailman/listinfo/python-list

Did you type the code using idle, or the default python interactive
console?  If you did, please do that again, and copy and paste your
code and the results here.  There is something amiss.

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What might cause my sample program to forget that already imported datetime?

2020-10-12 Thread Joel Goldstick
On Mon, Oct 12, 2020 at 6:14 AM Steve  wrote:
>
> At the top of my sample program, I have:
>
> import datetime
> from datetime import *

This second import tramples on the first.  What happens if you remove it?
>
> But import datetime also has to be entered on line 21 as shown.
> The error is printed at the bottom of the code.
> Why does the code seem to forget that I have already imported datetime?
> =
> import datetime
> from datetime import *
>
> d2 =  datetime.now()
> d2i = d2.isoformat()
>
> with open("TimeDate.txt", 'r') as infile:
>  for BottleInfo in infile: # loop to find each line in the file for that
> dose
>BottleInfo = BottleInfo.strip()
>
>if ((BottleInfo[0:3]== "LBD")):
> BottleData = BottleInfo[0:43].strip()
>
> BottleDataA = BottleData[4:14].strip()
> BottleDataB = BottleData[16:30].strip()
> BottleDataC = BottleDataA + " " + BottleDataB
> print("BottleDataC = <" + BottleDataC + ">")
> print()
> d1 = BottleDataC
>
> import datetime  #Why does this have to be here? line 21
>
> dto = datetime.datetime.strptime(d1, '%Y-%m-%d %H:%M:%S.%f')

With the second import the above line will work if you do this:
dto = datetime.strptime(d1, '%Y-%m-%d %H:%M:%S.%f')
> dti = dto.isoformat()
>
> HoursDiff = int((d2-dto).total_seconds()/3600)
> print("HoursDiff = " + str(HoursDiff))
> print()
>
> TimeDateInfo=open("TimeDate.txt", "a")
> TimeDateInfo.write("{0:>5} {1:>25} {2:>5}\n".format ("LBD", d2i, HoursDiff))
> TimeDateInfo.close()
>
> print("Done")
>
> """
> This is the error I get if I comment out line 21:
>
> Traceback (most recent call last):
>   File "F:/Med Insulin codes A/A TEST 10-07-2020/ReadWriteTimeDate POSIX
> Samplea.py", line 38, in 
> dto = datetime.datetime.strptime(d1, '%Y-%m-%d %H:%M:%S.%f')
> AttributeError: type object 'datetime.datetime' has no attribute 'datetime'
> """
> This code will be copied into another program as a function and the presence
> of import datetime in line 21 causes another error.
>
> ==
> Footnote:
> The human brain is one of the most complex things known to man.
> according to the human brain.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-26 Thread Joel Goldstick
On Sat, Sep 26, 2020 at 2:01 AM Stephane Tougard via Python-list
 wrote:
>
>
> Hello All,
>
> I've been working with Perl a long time and recently started to use
> Python. I've been surprised by one behavior of Python.
>
> In Perl:
>
> ===PERL===
> #!/usr/pkg/bin/perl
>
> use strict;
>
> if(4 == 4)
> {
> my $name = "Stephane";
> print("$name\n"
> }
> print("Out $name\n");
> =
>
> This code will trigger an error because $name is declared inside the if
> and is not usable outside of the block code. That looks logic to me.
>
> ===PYTHON===
> #!/usr/local/bin/python
> if 4 == 4:
> name = "Stephane"
> print(name)
> pass
>
> print("Out {}".format(name))
> 
>
> The exact same code in Python works fine, the variable name is used
> outside of the if block even it has been declared inside.
>
> This does not look right to me. Can we change this behavior or is there
> any point to keep it this way ?
> --
> https://mail.python.org/mailman/listinfo/python-list


It looks like perl creates a local namespace inside the code suite of
the if statement.  Python namespace is function based.

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: About float/double type number in range.

2020-08-26 Thread Joel Goldstick
On Wed, Aug 26, 2020 at 3:43 AM ADITYA  wrote:
>
>Dear Sir/Ma’am
>
>I am requesting you to satisfy me about float number in Range function,
>because in the argument of range we can take integer but not double or
>float whenever double as well as float are integer in nature but when we
>use double/float in, it gives error that- “'float' object cannot be
>interpreted as an integer.” If we want to increment the number by half or
>quarter what can I do.
>
>For ex- Range(1,3,0.5) I want it gives Output as [1 1.5 2 2.5 3)
>

Take a look at this:
>>> l = [i/2 for i in range(2,7)]
>>> l
[1.0, 1.5, 2.0, 2.5, 3.0]
>>>
The first line is a list comprehension which is a convenient way to
produce a list by performing an operation on each element in range.

In your code, you set the end of the range to 3 which will not include
3.  It stops at 2.
>
>
>I am requesting to change the nature of increment number nature in above
>example so that we can increase the number with half or quarter any point
>value.
>
   if you want to increase by 1/4, use a range that is 4 times normal
integers. and divide each element by 4
>
>Your Sincerely
>
>Aditya Gautam
>
>Saharsa (Bihar)
>
>India
>
>Postal Code- 852201
>
>
>
>
>
>
>
>
>
>
>
>Sent from [1]Mail for Windows 10
>
>
>
>[2][IMG] Virus-free. [3]www.avg.com
>
> References
>
>Visible links
>1. https://go.microsoft.com/fwlink/?LinkId=550986
>2. 
> http://www.avg.com/email-signature?utm_medium=email_source=link_campaign=sig-email_content=emailclient
>    3. 
> http://www.avg.com/email-signature?utm_medium=email_source=link_campaign=sig-email_content=emailclient
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to remove "" from starting of a string if provided by the user

2020-08-11 Thread Joel Goldstick
On Tue, Aug 11, 2020 at 12:26 PM MRAB  wrote:
>
> On 2020-08-11 02:20, Ganesh Pal wrote:
>  > The possible value of stat['server2'] can be either (a)
> "'/fileno_100.txt'" or (b) '/fileno_100.txt' .
>  > How do I check if it the value was  (a) i.e string started and ended
> with a quote , so that I can use ast.literal_eval()
>  > >>> import ast
>  > >>> stat = {}
>  > >>> stat['server2']  = "'/fileno_100.txt'"
>  > >>> stat['server2'] = ast.literal_eval(stat['server2'])
>  > >>> print  stat['server2']
>  > /fileno_100.txt
>  > >>>
>  > >>> if stat['server2'].startswith("\"") and
> stat['server2'].endswith("\""):
>  > ...stat['server2'] = ast.literal_eval(stat['server2'])
>  > ...
>  > >>>
>  > I tried startswith() and endswith(), doesn't seem to work ?. Is there
> a simpler way ?
>  >
>
> I gave 2 possible solutions. Try the first one, which was to use the
> .strip method to remove the quotes.
>
> The reason that startswith and endwith don't seem to work is that you're
> checking for the presence of " (double quote) characters, but, according
> to what you've posted, the strings contain ' (single quote) characters.
>
> [snip]
>
> --
> https://mail.python.org/mailman/listinfo/python-list

I'm assuming that you don't want the string to start with single
quote, doublequote, or the other way around.  If you have that
situation, strip the first and last characters:

>>> s = "'Starts with double quote'"
>>> s1 = '"Starts with single quote"'
>>> if s[:1] == "'" or s[:1] == '"':
...   s_stripped = s[1:-1]
...
>>> s_stripped
'Starts with double quote'
>>> if s1[:1] == "'" or s1[:1] == '"':
...   s_stripped = s1[1:-1]
...
>>> s_stripped
'Starts with single quote'
>>>

This assumes the quotes match at both ends of the string
-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I need to study Python

2020-06-26 Thread Joel Goldstick
On Thu, Jun 25, 2020 at 8:18 PM Igor Korot  wrote:
>
> Hi,
> Just sign-up for a local community college.
> Will be easier and u will keep motivation...
>
> Thank you.
>
>
> On Thu, Jun 25, 2020, 6:49 PM  wrote:
>
> > Hey, I'm a completely noob.
> > I want to learn python, how can i or where can i study python?
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> --
> https://mail.python.org/mailman/listinfo/python-list

start with python.org

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strings: double versus single quotes

2020-05-19 Thread Joel Goldstick
On Tue, May 19, 2020 at 2:27 PM Chris Angelico  wrote:
>
> On Wed, May 20, 2020 at 4:21 AM Manfred Lotz  wrote:
> >
> > Hi there,
> > I am asking myself if I should preferably use single or double quotes
> > for strings?
> >
> > If I need a single quote in a string I would use double quotes for the
> > whole string and vice versa. For f-strings I mostly see double
> > quotes but single quotes would work as well I think.
> >
> > Is there a recommendation?
> >
>
> Nothing strong. I tend to use double quotes because I have a
> background in C (where double quotes are for strings, single quotes
> for characters), and double quotes are the recommendation for
> docstrings (see PEP 258). If you tend to work a lot with SQL, you
> might prefer single quotes. Use whatever makes you happy.
>
I thought triple quotes are for docstrings?
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cartopy error

2020-05-12 Thread Joel Goldstick
On Tue, May 12, 2020 at 12:13 PM J Conrado  wrote:
>
>
>
> Hi,
>
>
> Please, what can I do to solve this error:
>
>
> import cartopy, cartopy.crs as ccrs  # Plot maps

# check your spelling.  Did you mean cartopy.ccrs?

>File
> "/home/conrado/anaconda3/envs/myenv/lib/python3.8/site-packages/cartopy/__init__.py",
> line 96, in 
>  import cartopy.crs
>File
> "/home/conrado/anaconda3/envs/myenv/lib/python3.8/site-packages/cartopy/crs.py",
> line 36, in 
>  from cartopy._crs import (CRS, Geodetic, Globe, PROJ4_VERSION,
> ImportError: libproj.so.19: cannot open shared object file: No such file
> or directory
>
>
> Thank you,
>
>
> Conrado
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strong AI Steps for Coding AI Mind in Python

2020-04-14 Thread Joel Goldstick
nking Module -- http://ai.neocities.org/EnThink.html
>
> The English thinking module calls such subordinate modules as the Indicative 
> module for a declarative sentence or the InFerence module for automated 
> reasoning.
>
>
> 31. Motorium Robot Motor Memory Module -- 
> http://ai.neocities.org/Motorium.html
>
> As soon as you have sensory memory for audition, it is imperative to include 
> motor memory for action. The polarity of robot-to-world is about to become a 
> circularity of robot - motorium - world - sensorium - robot. If you have been 
> making robots longer than you have been making minds, you now need to 
> engrammatize whatever motor software routines you may have written for your 
> particular automaton. You must decouple your legacy motor output software 
> from whatever mindless stimuli were controlling the robot and you must now 
> associate each motor output routine with memory engram nodes accreting over 
> time onto a lifelong motor memory channel for your mentally awakening robot. 
> If you have not been making robots, implement some simple motor output 
> function like emitting sounds or moving in four directions across a real or 
> virtual world.
>
> 32. Volition module for robot free will -- 
> http://ai.neocities.org/Volition.html
>
> In your robot software, de-link any direct connection that you have hardcoded 
> between a sensory stimulus and a motor initiative. Force motor execution 
> commands to transit through your stubbed-in Volition module, so that future 
> versions of your thought-bot will afford at least the option of incorporating 
> a sophisticated algorithm for free will in robots. If you have no robot and 
> you are building a creature of pure reason, nevertheless include a Volition 
> stub for the sake of AI-Complete design patterns.
>
>
> 33. The SeCurity module.
>
> The SeCurity module is not a natural component of the mind, but rather a 
> machine equivalent of the immune system in a human body. When we have 
> advanced AI robots running factories to fabricate even more advanced AI 
> robots, let not the complaint arise that nobody bothered to build in any 
> security precautions. Stub in a SeCurity module and let it be called from the 
> MainLoop by uncommenting any commented-out mention of SeCurity in the 
> MainLoop code. Inside the new SeCurity module, insert a call to ReJuvenate 
> but immediately comment-out the call to the not-yet-existent ReJuvenate 
> module. Also insert into SeCurity any desired code or diagnostic messages 
> pertinent to security functions.
>
> http://ai.neocities.oprg/AiSteps.html
> --
> https://mail.python.org/mailman/listinfo/python-list

Is there a question here?  It looks like a pretty involved homework assignment

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get a place's longitude and latitude?

2020-02-24 Thread Joel Goldstick
On Mon, Feb 24, 2020 at 11:10 AM Aakash Jana  wrote:
>
> You might use webscraping with requests and beautiful soup to scrape up
> some website for that gives such utility
>
>
> On Mon, 24 Feb 2020, 9:36 pm Souvik Dutta 
> > Hi guys I want to make a program that kinda sends an sos message with the
> > measures of longitude and latitude (which is super inconvenient) to
> > someone. How can I do that I mean how can I get the longitude and latitude?
> > Any help would be appreciated.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> --
> https://mail.python.org/mailman/listinfo/python-list

I found this article for using a raspberry pi and a gps card.  It
might give you some ideas:

https://tutorials-raspberrypi.com/build-raspberry-pi-gps-location-navigation-device/

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ERROR in loading data

2020-02-04 Thread Joel Goldstick
On Tue, Feb 4, 2020 at 9:51 AM  wrote:
>
> #load the training and testing data, then scale it into the
> # range [0, 1]
> print("[INFO] loading  ADNI data...")
> ((trainX, trainY), (testX, testY)) = '/content/gdrive/My 
> Drive/3_Classes/'.loads_data()

What is the class of the .loads)data() method?  I don't think it is a
string representing a file path.  Look in the docs for .loads_data()
to see what you are doing wrong.  That looks like it might be a numpy
> trainX = trainX.astype("float") / 255.0
> testX = testX.astype("float") / 255.0
>
> # initialize the label names for the  ADNI dataset
> labelNames = ["outAD", "outCN", "outMCI"]
> When i try to run this code I got the following error.
>
> [INFO] loading  ADNI data...
> ---
> AttributeErrorTraceback (most recent call last)
>  in ()
>   1 print("[INFO] loading  ADNI data...")
> > 2 ((trainX, trainY), (testX, testY)) = '/content/gdrive/My 
> Drive/3_Classes/'.loads_data()
>   3 trainX = trainX.astype("float") / 255.0
>   4 testX = testX.astype("float") / 255.0
>   5
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: installation issue.

2020-01-20 Thread Joel Goldstick
On Mon, Jan 20, 2020 at 5:29 AM NIT Application  wrote:
>
> Hi Team,
>
> I am not able to select the path on command prompt. It gives me an error that 
> python is not recognized as an internal or  external command.
> Please help me with this to set up and perform my activities.
>
> Regards,
> Sandesh Kamble
>
>
> Sent from Mail for Windows 10
>
> --
> https://mail.python.org/mailman/listinfo/python-list

if you are typing something like this:

cd /mydir

but you are in the python shell, and not to linux shell

copy and paste your screen display


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extract all words between two keywords in .txt file (Python)

2019-12-11 Thread Joel Goldstick
On Wed, Dec 11, 2019 at 1:31 PM Ben Bacarisse  wrote:
>
> A S  writes:
>
> > I would like to extract all words within specific keywords in a .txt
> > file. For the keywords, there is a starting keyword of "PROC SQL;" (I
> > need this to be case insensitive) and the ending keyword could be
> > either "RUN;", "quit;" or "QUIT;". This is my sample .txt file.
> >
> > Thus far, this is my code:
> >
> > with open('lan sample text file1.txt') as file:
> > text = file.read()
> > regex = re.compile(r'(PROC SQL;|proc sql;(.*?)RUN;|quit;|QUIT;)')
> > k = regex.findall(text)
> > print(k)
>
> Try
>
>   re.compile(r'(?si)(PROC SQL;.*(?:QUIT|RUN);)')
>
> Read up one what (?si) means and what (?:...) means..  You can do the
> same by passing flags to the compile method.
>
> > Output:
> >
> > [('quit;', ''), ('quit;', ''), ('PROC SQL;', '')]
>
> Your main issue is that | binds weakly.  Your whole pattern tries to
> match any one of just four short sub-patterns:
>
> PROC SQL;
> proc sql;(.*?)RUN;
> quit;
> QUIT;
>
> --
> Ben.
> --
> https://mail.python.org/mailman/listinfo/python-list

Consider using python string functions.

1. read your string, lets call it s.
2 . start = s.find("PROC SQL:"
 This will find the starting index point.  It returns and index
3. DO the same for each of the three possible ending  strings.  Use if/else
4. This will give you your ending index.
5 slice the included string, taking into account the start is start +
len("PROC SQL;") and the end is the ending index - the length of
whichever string ended in your case

Regular expressions are powerful, but not so easy to read unless you
are really into them.
-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named Adafruit_SSD1306 Update

2019-12-05 Thread Joel Goldstick
On Thu, Dec 5, 2019 at 3:31 PM RobH  wrote:
>
> On 05/12/2019 19:40, Rhodri James wrote:
> > On 05/12/2019 19:30, Rhodri James wrote:
> >> On 05/12/2019 18:49, RobH wrote:
> >>> Update:
> >>> I did python3 Internet.py
> >>> and now only get this error:
> >>>
> >>> pi@raspberrypi:~/Downloads $ python3 Internet.py
> >>>File "Internet.py", line 24
> >>>  font = ImageFont.truetype( 'Minecraftia.ttf', 35)
> >>>  ^
> >>> TabError: inconsistent use of tabs and spaces in indentation
> >>>
> >>> I cannot see what is wrong, as the text is all lined up with that
> >>> above and below:
> >>
> >> The problem will be that you have a mix of tabs and spaces in your
> >> indentation.  This causes problems because some people don't think
> >> that the One True Tab Width is 8 characters ;-) so to them the
> >> indentation looks ragged.  Worse, when they mix tabs and spaces, code
> >> that looks to be at the same indentation level to them looks different
> >> to the interpreter.  The decision was taken a while ago that Python
> >> should put its foot down about this, and demand that we use either all
> >> tabs or all spaces for our indentation.  That's what you've fallen
> >> foul off; there must be a mix of tabs and spaces in that line!
> >
> > Or more likely you've used tabs on that line and spaces elsewhere, or
> > vice versa.  I should have remember to say that, sorry.
> >
>
> Ok thanks for the explanation there, and I have placed the cursor at the
> beginning of the first indented line. Moving down 1 line at a time ,
> each line is at the same position upto line 157 in the authors code .
> Then it is closer in to the edge upto line 190, where it goes back out
> again.
>
> What is my best course of action here now.
>
> --
> https://mail.python.org/mailman/listinfo/python-list

google or duckduckgo or whatever your text editor and tabs to spaces..
there is probably an easy way to convert the file

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Resources related with web security

2019-11-26 Thread Joel Goldstick
On Tue, Nov 26, 2019 at 2:23 PM Mr. Gentooer  wrote:
>
> > > On Mon, 25 Nov 2019 21:25:12 + (UTC), Pycode 
> > > declaimed the following:
> > >
> > > comp.lang.python gmane.comp.python.general
>
> how do you access these in a reasonable way?
>
> --
> https://mail.python.org/mailman/listinfo/python-list

I'm thinking this is a troll or a turing machine experiment?

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python startup failure problem

2019-11-01 Thread Joel Goldstick
On Fri, Nov 1, 2019 at 8:59 AM Tanay Dandekar
 wrote:
>
> -- Forwarded message -
> From: Tanay Dandekar 
> Date: Thu, Oct 31, 2019 at 10:30 PM
> Subject: python startup failure problem
> To: 
>
>
> Dear Sir,
>
> Please find attached photo of Python failure detail.
>
> please solve this problem as soon as possible.
>
> thanking you,
>
> Regard
> tanay
> --
> https://mail.python.org/mailman/listinfo/python-list
Dear Tanay,

Some, perhaps most people, might find it rude to assume that people
here will solve your problem!  This is a mailing list where people
will help you solve python problems.  You need to do your part as
well.  Photos, or any attachments are removed before your message is
sent to list members.  Please copy and paste your traceback from when
you run your code, and describe the problems you are having.  Also
nice is your OS, python version.



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TypeError: unhashable type: 'list'

2019-10-23 Thread Joel Goldstick
On Wed, Oct 23, 2019 at 3:54 AM joseph pareti  wrote:
>
> I am experimnenting with this (reproducer) code:
> pattern_eur= ['Total amount']

the above line can't contain a list -- just a string

see help(re.search)

> mylines = []# Declare an empty list.
> with open ('tmp0.txt', 'rt') as myfile: # Open tmp.txt for reading text.
> for myline in myfile:   # For each line in the file,
> mylines.append(myline.rstrip('\n')) # strip newline and add to list.
> for element in mylines: # For each element in the list,
>match_C = re.search(pattern_eur, element)
>if match_C:
>  element = element + 2
>  print(element)
> --
> the input file being:
> $ cat tmp0.txt
> line 0
> line 1
> Total amount
>
> 5.00
> linex
> line z
> line c
> Total amount
>
> 43598
> line
> line m
>
> Total amount
>
> 32000
> line end -1
> line end 0
> line end 1
> line end 2
>
> --
>
> My intent is to locate the line containing "Total amount", skip the next
> line, then print the eur value. The program terminates as follows:
> Traceback (most recent call last):
>   File "search_then_advance.py", line 8, in 
> match_C = re.search(pattern_eur, element)
>   File
> "c:\Users\joepareti\Miniconda3\pkgs\python-3.7.1-h8c8aaf0_6\lib\re.py",
> line 183, in search
> return _compile(pattern, flags).search(string)
>   File
> "c:\Users\joepareti\Miniconda3\pkgs\python-3.7.1-h8c8aaf0_6\lib\re.py",
> line 276, in _compile
> return _cache[type(pattern), pattern, flags]
> TypeError: unhashable type: 'list'
>
> Thanks for any insigths --
> --
> Regards,
> Joseph Pareti - Artificial Intelligence consultant
> Joseph Pareti's AI Consulting Services
> https://www.joepareti54-ai.com/
> cell +49 1520 1600 209
> cell +39 339 797 0644
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: System error while Installing Python 3.7.4 (64 bit).

2019-10-22 Thread Joel Goldstick
On Tue, Oct 22, 2019 at 10:33 AM svenkatabhargava reddy
 wrote:
>
> Hi Team Python,
>
> Getting system error while trying to install python 3.7.4 version, also
> attaching the screen shot of error along with the message. Hoping team will
> come back soon with the solution.
> [image: image.png]
>
>
> Thanks and Regards,
> S.V.Bhargava Reddy.
> --
> https://mail.python.org/mailman/listinfo/python-list

Images don't make it through on this mailing list.  Try to cut and
paste complete error message.  What OS

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Convert a scientific notation to decimal number, and still keeping the data format as float64

2019-10-21 Thread Joel Goldstick
On Mon, Oct 21, 2019 at 4:59 PM Chris Angelico  wrote:
>
> On Tue, Oct 22, 2019 at 7:41 AM  wrote:
> >
> > They ought to have a reason to make the program switch from pure decimal to 
> > scientific notation representation. I don't know that reason. Getting along 
> > with it.
> >
>
> This is JUST a default display representation. Nothing more. If you
> care about how something is displayed, just use a formatting tool.
> That's all you need to do.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list

Exactly!

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Convert a scientific notation to decimal number, and still keeping the data format as float64

2019-10-20 Thread Joel Goldstick
On Sun, Oct 20, 2019 at 6:06 PM  wrote:
>
>
> my statement may seem unlogical while evaluating and comparing the languages 
> as a whole..
>
> I thought when I give a small number into the programme , the more decimals I 
> can see after the dot as an output, the more human readable it is.
>
> when I see a bunch of numbers with 'e' s I know the numbers are small but it 
> is hard for me to compare it to other numbers with 'e'. , specially with the 
> human eye.
>
> I dont know much about scala actually. I have just have tried to give 0.0001 
> and it returned a presentation with an 'e' .whereas python takes 0.0001 and 
> gives 0.0001 . it made me think python is better in that specific subject.
>
> However, python though starts to give 'e' number when 5 decimals are given as 
> input.  Although  there can be systems around which are better in this 
> subject other things I can achieve in python overrides some disadvantages.
> --
> https://mail.python.org/mailman/listinfo/python-list

The question here has nothing to do with a programming language.  As a
bystander, this thread is interesting in a strange way.  We have a
poster who has no programming experience, no background to understand
floating point numbers, no concept of the difference between an
internal computer usable representation of a number, and a human
readable representation.

I am sure I am much older than many people here.  When I first learned
about computers, and programming, and number formats, I also learned
about binary numbers, how computers perform arithmetic calculations at
a bit level, and lots of things no one really cares about today.  Fast
forward and we have a person who (I'm guessing) is trying to write a
program to complete some schoolwork in a subject far afield for
learning about computer programming.  Although the problem to be
solved seems to be statistical or somehow numeric, the poster doesn't
seem to understand so much about the math either, having gone haywire
over exponential notation.   It is great that computers are so
commonplace that problems can be studied and solved with them when the
problem solver has so little basic understanding of the tool he is
using.  But the thread shows the downside to lacking the basics about
the tool.

I don't mean any negative connotation toward to original poster.  The
problem he poses is legitimate, and confounding for him and for those
who have tried to answer him here since there are these hard
disconnects about concepts that are required to understand the
question.  Its a problem that everyone confronts daily -- No one
really knows how anything works under the hood.   Think: car, toaster,
microwave oven, Facebook algorithms, light bulbs, and on and on

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: a &= b

2019-10-04 Thread Joel Goldstick
On Fri, Oct 4, 2019 at 5:01 AM Hongyi Zhao  wrote:
>
> Hi,
>
> Could you please give me some more hints on:
>
> a &= b
>
> It's very difficult for me to understand.
> --
> https://mail.python.org/mailman/listinfo/python-list

& is bitwise And.  a &= b is equivalent to a = a & b


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: phyton

2019-09-10 Thread Joel Goldstick
On Tue, Sep 10, 2019 at 8:10 AM tim.gast--- via Python-list
 wrote:
>
> Op dinsdag 10 september 2019 13:03:46 UTC+2 schreef tim...@quicknet.nl:
> > Hi everybody,
> >
> > For school i need to write the right code to get the following outcome.
> > Can someone help me with this
> > I can't find a solution to link the word high to 1.21.
> >
> > 11 print(add_vat(101, 'high'))
> > 12 print(add_vat(101, 'low'))
> >
> > Outcome:
> >
> > 122.21
> > 110.09
> >
> > Thanks!
>
> I have tried to get it with the dictonary but it doesn't work
> You are right that it is homework and i am trying to figure it out but i cant 
> find anything on the internet that can help me.
> What am i doing wrong.
>
> my_dict('high':21,'low':5)
>
> def add_vat(amount, vat_rate):
>   berekening = amount * (1+vat_rate)
>   return round(berekening,2)
>
> print(add_vat(101, 'high'))
> --
> https://mail.python.org/mailman/listinfo/python-list
These code snippets don't run  Can you paste your complete code that
runs, with the output you get?



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: issue in handling CSV data

2019-09-07 Thread Joel Goldstick
On Sat, Sep 7, 2019 at 8:28 PM Joel Goldstick  wrote:
>
> On Sat, Sep 7, 2019 at 8:21 PM Sharan Basappa  
> wrote:
> >
> > I am trying to read a log file that is in CSV format.
> >
> > The code snippet is below:
> >
> > ###
> > import matplotlib.pyplot as plt
> > import seaborn as sns; sns.set()
> > import numpy as np
> > import pandas as pd
> > import os
> > import csv
> > from numpy import genfromtxt
> >
> > # read the CSV and get into X array
> > os.chdir(r'D:\Users\sharanb\OneDrive - HCL Technologies 
> > Ltd\Projects\MyBackup\Projects\Initiatives\machine 
> > learning\programs\constraints')
> > X = []
> > #with open("constraints.csv", 'rb') as csvfile:
> > #reader = csv.reader(csvfile)
> > #data_as_list = list(reader)
> > #myarray = np.asarray(data_as_list)
> >
> > my_data = genfromtxt('constraints.csv', delimiter = ',', dtype=None)
> > print (my_data)
> >
> > my_data_1 = np.delete(my_data, 0, axis=1)
> > print (my_data_1)
> >
> > my_data_2 = np.delete(my_data_1, 0, axis=1)
> > print (my_data_2)
> >
> > my_data_3 = my_data_2.astype(np.float)
> > 
> >
> > Here is how print (my_data_2) looks like:
> > ##
> > [['"\t"81' '"\t5c']
> >  ['"\t"04' '"\t11']
> >  ['"\t"e1' '"\t17']
> >  ['"\t"6a' '"\t6c']
> >  ['"\t"53' '"\t69']
> >  ['"\t"98' '"\t87']
> >  ['"\t"5c' '"\t4b']
> > ##
> >
> > Finally, I am trying to get rid of the strings and get array of numbers 
> > using Numpy's astype function. At this stage, I get an error.
> >
> > This is the error:
> > my_data_3 = my_data_2.astype(np.float)
> > could not convert string to float: " "81
> >
> > As you can see, the string "\t"81 is causing the error.
> > It seems to be due to char "\t".
> >
> > I don't know how to resolve this.
> >
> > Thanks for your help.
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
>
> how about (strip(my_data_2).astype(np.float))
>
> I haven't used numpy, but if your theory is correct, this will clean
> up the string
>
oops, I think I was careless at looking at your data.  so this doesn't
seem like such a good idea
> --
> Joel Goldstick
> http://joelgoldstick.com/blog
> http://cc-baseballstats.info/stats/birthdays



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: issue in handling CSV data

2019-09-07 Thread Joel Goldstick
On Sat, Sep 7, 2019 at 8:21 PM Sharan Basappa  wrote:
>
> I am trying to read a log file that is in CSV format.
>
> The code snippet is below:
>
> ###
> import matplotlib.pyplot as plt
> import seaborn as sns; sns.set()
> import numpy as np
> import pandas as pd
> import os
> import csv
> from numpy import genfromtxt
>
> # read the CSV and get into X array
> os.chdir(r'D:\Users\sharanb\OneDrive - HCL Technologies 
> Ltd\Projects\MyBackup\Projects\Initiatives\machine 
> learning\programs\constraints')
> X = []
> #with open("constraints.csv", 'rb') as csvfile:
> #reader = csv.reader(csvfile)
> #data_as_list = list(reader)
> #myarray = np.asarray(data_as_list)
>
> my_data = genfromtxt('constraints.csv', delimiter = ',', dtype=None)
> print (my_data)
>
> my_data_1 = np.delete(my_data, 0, axis=1)
> print (my_data_1)
>
> my_data_2 = np.delete(my_data_1, 0, axis=1)
> print (my_data_2)
>
> my_data_3 = my_data_2.astype(np.float)
> 
>
> Here is how print (my_data_2) looks like:
> ##
> [['"\t"81' '"\t5c']
>  ['"\t"04' '"\t11']
>  ['"\t"e1' '"\t17']
>  ['"\t"6a' '"\t6c']
>  ['"\t"53' '"\t69']
>  ['"\t"98' '"\t87']
>  ['"\t"5c' '"\t4b']
> ##
>
> Finally, I am trying to get rid of the strings and get array of numbers using 
> Numpy's astype function. At this stage, I get an error.
>
> This is the error:
> my_data_3 = my_data_2.astype(np.float)
> could not convert string to float: " "81
>
> As you can see, the string "\t"81 is causing the error.
> It seems to be due to char "\t".
>
> I don't know how to resolve this.
>
> Thanks for your help.
>
> --
> https://mail.python.org/mailman/listinfo/python-list

how about (strip(my_data_2).astype(np.float))

I haven't used numpy, but if your theory is correct, this will clean
up the string


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to remove a string from a txt file?

2019-09-04 Thread Joel Goldstick
On Wed, Sep 4, 2019 at 11:11 AM Spencer Du  wrote:
>
> Hi
>
> I want to remove a string from a txt file and then print out what I have 
> removed. How do I do this.
>
> The txt file is in this format and should be kept in this format.
>
> txt.txt:
> laser,cameras,
>
> Thanks
> --
> https://mail.python.org/mailman/listinfo/python-list

read the file line by line.  if it doesn't contain your string, write
it to a new file.  for each line, use string functions to find the
string you want to remove.  One way is to split on ',' or use
csvreader to get a list of words between comma.  Print the one you
like and join the values on each side of the text you are looking for.
Write that to a file

Lather, rinse and repeat

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed urgently for running some code!!!!

2019-09-03 Thread Joel Goldstick
On Tue, Sep 3, 2019 at 1:38 PM Dennis Lee Bieber  wrote:
>
> On Mon, 2 Sep 2019 08:05:14 -0700 (PDT), Spencer Du
>  declaimed the following:
>
> >Hi
> >
> >I want to execute
> >
> >"from devicesEmbedded import *": in GUI.py after all code in GUI.py is run. 
> >Also how do I make the devicesEmbedded.py reload and run when a txt file is 
> >created in the name of "list_of_devices.txt" in the GUI.py python program.
> >
> Reload is one of the least effective features. Especially when you 
> have
> bound names locally within modules. "... import *" binds names locally.
> Reloading a changed module creates a new module entry in Python's run-time,
> but any local names still refer to the old module contents.
>
> Please consider reading the documentation:
> https://docs.python.org/3/library/importlib.html
>
> """
>  importlib.reload(module)
>
> Reload a previously imported module. The argument must be a module
> object, so it must have been successfully imported before. This is useful
> if you have edited the module source file using an external editor and want
> to try out the new version without leaving the Python interpreter. The
> return value is the module object (which can be different if re-importing
> causes a different object to be placed in sys.modules).
>
> When reload() is executed:
>
> Python module’s code is recompiled and the module-level code
> re-executed, defining a new set of objects which are bound to names in the
> module’s dictionary by reusing the loader which originally loaded the
> module. The init function of extension modules is not called a second time.
>
> As with all other objects in Python the old objects are only
> reclaimed after their reference counts drop to zero.
>
> The names in the module namespace are updated to point to any new
> or changed objects.
>
> Other references to the old objects (such as names external to the
> module) are not rebound to refer to the new objects and must be updated in
> each namespace where they occur if that is desired.
> """
>
> NOTE the last paragraph. This means you should NOT be using "... import *"
> syntax for anything you might want to have reloaded. Instead use "import
> modulename" and everywhere you access something in that module use the long
> form "modulename.something". This way, when it is reloaded, "modulename"
> will reference the new contents.
>
>
> As for detecting file changes... You will have to periodically check
> the time-stamp (modification time) of the file, and if it changes, reread
> the file.
>
>
>
>
>
> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Spencer, for the past month (almost) you have been sending "urgent"
requests for people here to write code for you.  You've already
decided what needs to be done, but you haven't really explained what
you want to do.  You don't respond to other's responses for further
clarification, or with your progress.  You basically repeat the same
urgent request.  Please don't do this.  There are many python experts
here who will help you, but getting someone to write your code for you
when you can't really explain what your goal is will get you nowhere,
especially since you claim this is for your job.

To me, its an odd thing to want to do imports depending on a file's
contents.  But maybe its a good idea.  However, you can just import
all of the modules you might expect to need, and ignore if they aren't
present with a suitable try/except block.   Try explaining the bigger
picture of what you are trying to do, and maybe you can gain some
incite into a better way of proceeding.  I'm afraid it looks like you
have been cutting and pasting without understanding what your code's
design is all about.  I could be totally wrong.  good luck

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TypeError: loadtxt() got an unexpected keyword argument 'max_rows'

2019-09-03 Thread Joel Goldstick
On Tue, Sep 3, 2019 at 12:06 PM alberto  wrote:
>
> Hi,
> I produce a script to elaborate data
>
> but command line $ python3.4 PlotnhvsvdBTP1.py
>
> I have this error
>
> Traceback (most recent call last):
> File "PlotnhvsvdBTP1.py", line 31, in 
> UCvol = np.loadtxt(outputtransfile,skiprows=26,max_rows=1,usecols=[1])
> TypeError: loadtxt() got an unexpected keyword argument 'max_rows'
>
> How could fix it?
>
> I attacched my files
>
> https://drive.google.com/file/d/1PgOcuEMFsaAuKTsbU0i0gwg04mDCJJoK/view?usp=sharing
> https://drive.google.com/file/d/13E7vcGQtrOS1lw9RupGThGQ2vSGRfTFG/view?usp=sharing
> https://drive.google.com/file/d/1Z6GKYtHthAyPO3wFHUFK10QweRpclu29/view?usp=sharing
>
> regard
>
> Alberto

Please don't attach files.  Cut and paste code as text into email body
along with copy and pasted traceback.

That said I found this:.. versionadded:: 1.14.0
max_rows : int, optional

Check your version of loadtxt()?
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hi how do I import files inside a txt file?

2019-09-02 Thread Joel Goldstick
On Mon, Sep 2, 2019 at 9:21 AM Spencer Du  wrote:
>
> On Monday, 2 September 2019 15:03:52 UTC+2, Joel Goldstick  wrote:
> > On Mon, Sep 2, 2019 at 8:46 AM Spencer Du  wrote:
> > >
> > > On Monday, 2 September 2019 13:36:06 UTC+2, Pankaj Jangid  wrote:
> > > > Spencer Du  writes:
> > > >
> > > > > How do i import files inside a txt file if they exist in the current 
> > > > > directory?
> > > > >
> > > > > Here is the current code but I dont know how to do it correctly.
> > > > >
> > > > > import paho.mqtt.client as mqtt
> > > > > from mqtt import *
> > > > > import importlib
> > > > > import os
> > > > > import os.path
> > > > > # from stateMachine import *
> > > > >
> > > > > with open("list_of_devices.txt", "r") as reader:
> > > > > for item in reader:
> > > > > try:
> > > > > os.getcwd()
> > > > > print("hi")
> > > > > except:
> > > > > print("error")
> > > > >
> > > > > This is "list_of_devices.txt":
> > > > > test1,test2
> > > > >
> > > > > Each name refers to a python file.
> > > > >
> > > > My interpretation is that you want to read a file (list_of_devices.txt)
> > > > and this file contains names of other files and you want to read those
> > > > files as well and do something with them (read or print or whatever).
> > > >
> > > > You can approach it like this: write a function to read a file and work
> > > > on it. Like this,
> > > >
> > > > def fn(fname):
> > > > with open(fname, "r") as f:
> > > >  try:
> > > > # work with f
> > > >  except:
> > > > print("error")
> > > >
> > > > Then use this function in your code that you have writen. Like this
> > > >
> > > > with open("list_of_devices.txt", "r") as reader:
> > > >  for item in reader:
> > > >  try:
> > > > fn(item)
> > > >  except:
> > > > print("error")
> > > >
> > > > In the example that you gave, you have written contents of
> > > > "list_of_devices.txt" as
> > > >
> > > > test1,test2
> > > >
> > > > Take care to read them as comma separated. Or if you have control then
> > > > write them on separate lines.
> > > >
> > > > Regards.
> > > > --
> > > > Pankaj Jangid
> > >
> > > Hi Pankaj
> > >
> > > I dont understand so what is complete code then?
> > >
> > > Thanks
> > > Spencer
> > > --
> > > https://mail.python.org/mailman/listinfo/python-list
> >
> > Pardon me for guessing, but your question seems to imply that you know
> > how you want to do something .. but I'm not sure you have tackled your
> > problem correctly.
> >
> > My guess is:  Depending upon the names listed in a text file, you want
> > to do different imports into your program.   You don't yet know how to
> > read a file with python.
> >
> > First, when you run your program, python compiles it in order.  Since
> > you don't know what you want to import until after you run your
> > program, you can't import those modules.  You may be able to run a
> > program to read the module list, then have it output to a new file the
> > code you eventually want to run based on the modules you discovered.
> > That sounds cute in a way, but probably not in a good way.  You could
> > also surround import statements with try/except code that will import
> > what it can, and alert you when it can't
> >
> > Can you give us the bigger picture of what you want to accomplish?
> > This might lead to a better solution than the one you are thinking of
> > now
> >
> > --
> > Joel Goldstick
> > http://joelgoldstick.com/blog
> > http://cc-baseballstats.info/stats/birthdays
>
> Hi
>
> I have a txt file which contains the names of files. They are .py files. I 
> want to import them into a python file if they exists in current directory 
> and if the name of file does not exist then print out error and not import. 
> How do I do this?
>
> Thanks
> Spencer

Here is a discussion on Stack overflow that lays out how you can
dynamically import files.  This should get you started in the right
direction.  First, see if you can write code to read the file, and
retrieve the names of the modules you want to import.   Come back if
you stumble with your code for that

https://stackoverflow.com/questions/301134/how-to-import-a-module-given-its-name-as-string
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hi how do I import files inside a txt file?

2019-09-02 Thread Joel Goldstick
On Mon, Sep 2, 2019 at 8:46 AM Spencer Du  wrote:
>
> On Monday, 2 September 2019 13:36:06 UTC+2, Pankaj Jangid  wrote:
> > Spencer Du  writes:
> >
> > > How do i import files inside a txt file if they exist in the current 
> > > directory?
> > >
> > > Here is the current code but I dont know how to do it correctly.
> > >
> > > import paho.mqtt.client as mqtt
> > > from mqtt import *
> > > import importlib
> > > import os
> > > import os.path
> > > # from stateMachine import *
> > >
> > > with open("list_of_devices.txt", "r") as reader:
> > > for item in reader:
> > > try:
> > > os.getcwd()
> > > print("hi")
> > > except:
> > > print("error")
> > >
> > > This is "list_of_devices.txt":
> > > test1,test2
> > >
> > > Each name refers to a python file.
> > >
> > My interpretation is that you want to read a file (list_of_devices.txt)
> > and this file contains names of other files and you want to read those
> > files as well and do something with them (read or print or whatever).
> >
> > You can approach it like this: write a function to read a file and work
> > on it. Like this,
> >
> > def fn(fname):
> > with open(fname, "r") as f:
> >  try:
> > # work with f
> >  except:
> > print("error")
> >
> > Then use this function in your code that you have writen. Like this
> >
> > with open("list_of_devices.txt", "r") as reader:
> >  for item in reader:
> >  try:
> > fn(item)
> >  except:
> > print("error")
> >
> > In the example that you gave, you have written contents of
> > "list_of_devices.txt" as
> >
> > test1,test2
> >
> > Take care to read them as comma separated. Or if you have control then
> > write them on separate lines.
> >
> > Regards.
> > --
> > Pankaj Jangid
>
> Hi Pankaj
>
> I dont understand so what is complete code then?
>
> Thanks
> Spencer
> --
> https://mail.python.org/mailman/listinfo/python-list

Pardon me for guessing, but your question seems to imply that you know
how you want to do something .. but I'm not sure you have tackled your
problem correctly.

My guess is:  Depending upon the names listed in a text file, you want
to do different imports into your program.   You don't yet know how to
read a file with python.

First, when you run your program, python compiles it in order.  Since
you don't know what you want to import until after you run your
program, you can't import those modules.  You may be able to run a
program to read the module list, then have it output to a new file the
code you eventually want to run based on the modules you discovered.
That sounds cute in a way, but probably not in a good way.  You could
also surround import statements with try/except code that will import
what it can, and alert you when it can't

Can you give us the bigger picture of what you want to accomplish?
This might lead to a better solution than the one you are thinking of
now

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How should we use global variables correctly?

2019-08-23 Thread Joel Goldstick
On Fri, Aug 23, 2019 at 4:00 AM Windson Yang  wrote:
>
> Thank you all. I agreed with Frank that
>
> > It would make sense to use the 'global' keyword if you have a module
> with various functions, several of which refer to 'foo', but only one of
> which changes the value of 'foo'.
>
> I also found an example in cpython/lib/gettext.py, only 'textdomain
> function' can change '_current_domain', other functions just refer to it.
> So, it will be not evil or to use 'global' keyword correctly when there is
> only one function can change its value?
>
> Cameron Simpson  于2019年8月23日周五 下午3:15写道:
>

The problem with deciding that only one function can change the value,
is that someone else can change the other functions.  So, if you are
working alone, it won't be a problem, but once code with globals
enters the 'wild' all bets are off.


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Web framework for static pages

2019-08-13 Thread Joel Goldstick
On Tue, Aug 13, 2019 at 4:12 PM Morten W. Petersen  wrote:
>
> Hi Joel.
>
> I don't disagree with what you're saying, but is there a documented way of 
> making Django produce a neat set of static pages?
>
> It would be nice to use a web application framework to create pages, because 
> it would after that be easy to add a little bit of logic if a customer wants 
> it. A contact form, an order form, etc.

Django has a feature called static pages.. I'm not up to the latest,
but check that you.  Perhaps it will work for you

>
> Zope/Plone has its own set of features and applications I know well, if a 
> customer wants a dynamic website with a lot of logic (dynamic pages).
>
> -Morten
>
> Blogging at http://blogologue.com
> Tweeting at https://twitter.com/blogologue
> On Instagram https://instagram.com/morphexx
>
> tir. 13. aug. 2019, 21.08 skrev Joel Goldstick :
>>
>> On Tue, Aug 13, 2019 at 2:46 PM DL Neil  
>> wrote:
>> >
>> > On 14/08/19 2:26 AM, Grant Edwards wrote:
>> > > On 2019-08-13, Jon Ribbens via Python-list  
>> > > wrote:
>> > >
>> > >> If it's really that small then it sounds like what you are looking for
>> > >> is known as a "text editor".
>> > >
>> > > Bah.  Kids these days.
>> > >
>> > >$ cat > index.hmtl
>> >
>> > [roaring with laughter]
>> >
>> >
>> >
>> > Oh come now. Surely a person with your depth of experience realises that
>> > all cats have moved to Facebook and YouTube, leaving their HTML in
>> > yesterday's litter box?
>> >
>> > --
>> > Regards =dn
>> > --
>> > https://mail.python.org/mailman/listinfo/python-list
>>
>> pardon my drive by comment, but this is close to trolling.  Whatever
>> is offered is shot down.  XHTML seems to have been a road that went
>> nowhere because the browser makers didn't like it.  HTML5 seemed to be
>> a big step forward.  I used a program called Citydesk a long time ago
>> that I think could do what the op might like.  But its long gone.  I
>> think django could be used to make static pages quite easily. Its not
>> hard to learn, and in the event your client wants more, django can do
>> that too
>>
>> --
>> Joel Goldstick
>> http://joelgoldstick.com/blog
>> http://cc-baseballstats.info/stats/birthdays
>> --
>> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Web framework for static pages

2019-08-13 Thread Joel Goldstick
On Tue, Aug 13, 2019 at 2:46 PM DL Neil  wrote:
>
> On 14/08/19 2:26 AM, Grant Edwards wrote:
> > On 2019-08-13, Jon Ribbens via Python-list  wrote:
> >
> >> If it's really that small then it sounds like what you are looking for
> >> is known as a "text editor".
> >
> > Bah.  Kids these days.
> >
> >$ cat > index.hmtl
>
> [roaring with laughter]
>
>
>
> Oh come now. Surely a person with your depth of experience realises that
> all cats have moved to Facebook and YouTube, leaving their HTML in
> yesterday's litter box?
>
> --
> Regards =dn
> --
> https://mail.python.org/mailman/listinfo/python-list

pardon my drive by comment, but this is close to trolling.  Whatever
is offered is shot down.  XHTML seems to have been a road that went
nowhere because the browser makers didn't like it.  HTML5 seemed to be
a big step forward.  I used a program called Citydesk a long time ago
that I think could do what the op might like.  But its long gone.  I
think django could be used to make static pages quite easily. Its not
hard to learn, and in the event your client wants more, django can do
that too

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re:

2019-06-24 Thread Joel Goldstick
On Mon, Jun 24, 2019 at 4:13 AM Sagar Jape  wrote:
>
> I'm not able to install pip in my pc it gives following error. what should
> I do?
> --
> https://mail.python.org/mailman/listinfo/python-list

Copy and paste your session info.  The list doesn't show images.

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem in installing packages

2019-05-28 Thread Joel Goldstick
On Wed, May 29, 2019 at 1:17 AM Sri Tharun  wrote:
>
> Problem not resolved.Yet
>
> On Wed 29 May, 2019, 6:39 AM Tharun,  wrote:
>
> >
> >
> > >>> sudo apt-get update
> >
> >   File "", line 1
> >
> > sudo apt-get update
> >
> >^
> >
> > SyntaxError: invalid syntax
> >
> >
> >
> >
> >
> > This was the problem
> >
> > Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for
> > Windows 10
> >
> >
> >
> --
> https://mail.python.org/mailman/listinfo/python-list

It appears you are trying to execute a linux shell command while in
the python repl.  exit python, and try again

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question :)

2019-05-13 Thread Joel Goldstick
On Mon, May 13, 2019 at 8:33 AM Milos Vujcic
 wrote:
>
> Hi,
> I’m new into Python and Django thing and I’m having big problem with cmd  and 
> virtualenv command. Do I really need to use virtual environment  for making 
> Django/Python web apps because my cmd just won’t accept it. Can I skip 
> virtualenv and just start making things in Django?
>
You don't have to use a virtual environment.  If it is holding you
back, and you are just familiarizing yourself with Django, you should
be fine.  But as you develop different django applications that use
different libraries, you will find that using virtualenv keeps the
right things in the right places.  So after you get started with
Django, look into what your problems are with virtualenv.  Copy and
paste the commands you use to install it, and include the resulting
error messages.  You will get help here


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Losing words

2019-04-01 Thread Joel Goldstick
On Mon, Apr 1, 2019 at 11:16 AM John Doe  wrote:
>
> On 2019-04-01, Chris Angelico  wrote:
> >>
> >> I'm learning SOCKETS and working with Irc.
> >>  ---
> >>  s.send(bytes("PRIVMSG " + channel +" "+ message + "\n", "UTF-8"))
> >>  
> >>  When more than one word ( for example: This is a message)
> >>  in *message* it sends the FIRST word only "This" and skips the rest.
> >>  Any ideas how to solve the problem? I was seating on it on the night
> >>  but nothing came up.
> >
> > Does your message begin with a colon?
> >
> > You may need a lot more context here. I have no idea what you're
> > running into because one line of code is vastly insufficient.
> >
>
> Nah mate,
>
> def text():
> mess = input("> ")
> s.send(bytes("PRIVMSG " + " "+ channel + " " +  mess  + "\n", "UTF-8"))
>
>     text()
>

Is this a typo or are you calling text() from within text()?
>-
>
>> This is a message
>
>and it sends just first word in this example: "This".
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: trying to begin a code for web scraping

2019-02-19 Thread Joel Goldstick
On Tue, Feb 19, 2019 at 12:52 AM Drake Gossi  wrote:
>
> Hi everyone,
>
> I'm trying to write code to scrape this website
> <https://www.regulations.gov/document?D=ED-2018-OCR-0064-5403> (
> regulations.gov) of its comments, but I'm having trouble figuring out what
> to link onto in the inspect page (like when I right click on inspect with
> the mouse).
>
> Although I need to write code to scrape all 11,000ish of the comments
> related to this event (by putting a code in a loop?), I'm still at the
> stage of looking at individual comments. So, for example, with this comment
> <https://www.regulations.gov/document?D=ED-2018-OCR-0064-5403>, I know
> enough to right click on inspect and to look at the xml? (This is how much
> of a beginner I am--what am I looking at when I right click inspect?) Then,
> I control F to find where the comment is in the code. For that comment, the
> word I used control F on was "troubling." So, I found the comment buried in
> the xml
>
> But my issue is this. I don't know what to link onto to scrape the comment
> (and I assume that this same sequence of letters would apply to scraping
> all of the comments in general). I assume what I grab is GIY1LSJISD. I'm
> watching this video, and the person is linking onto "tr" and "td," but mine
> is not that easy. In other words, what is the most essential language (bit
> of xml? code), the copying of which would allow me to extract not only this
> comment, but all of the comments, were I to put this bit of language(/xml?)
> my code? ... ... soup.findALL ('?')
>
> In sum, what I need to know is, how do I tell my Python code to ignore all
> of the surrounding code and go straight in and grab the comment. Of course,
> I need to grab other things too like the name, category, date, and so on,
> but I haven't gotten that far yet. Right now, I'm just trying to figure out
> what I need to insert into my code so that I can get the comment.
>
> Help! I'm trying to learn code on the fly. I'm an experienced researcher
> but am new to coding. Any help you could give me would be tremendously
> awesome.
>
> Best,
> Drake
> --
> https://mail.python.org/mailman/listinfo/python-list


Beautiful soup is your friend here.  It can analyze the data within
the html tags on your scraped page.  But often javascript is used on
'modern' web pages so the page is actually not just html, but
javascript that changes the html.  For this you need another tool -- i
think one is called scrapy.  Others here probably have experience with
that.

Show a small snippet of your code that demonstrates at least one of
your coding problems.
-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The sum of ten numbers inserted from the user

2019-02-07 Thread Joel Goldstick
On Thu, Feb 7, 2019 at 6:31 AM ^Bart  wrote:
>
> I thought something like it but doesn't work...
>
> for n in range(1, 11):
>  x = input("Insert a number: ")

The above, keeps replacing x with each input value.  You don't want
that.  Think about appending the input value to a list
>
> for y in range(x):
>  sum = y
>
Here again you are replacing sum with each value of y.  And think
further about what the value of y is for each iteration.

>  print ("The sum is: ",y)

You should really be asking this sort of question in the python-tutor
mailing list.  You should also use print function in your loops to
learn what is really going on.



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



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Exercize to understand from three numbers which is more high

2019-01-25 Thread Joel Goldstick
On Fri, Jan 25, 2019 at 7:16 AM Dan Purgert  wrote:
>
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA256
>
> ^Bart wrote:
> >
> > if number1 > number2 and number1 > number3:
> >  print("Max number is: ",number1)
> >
> > if number2 > number1 and number2 > number3:
> >  print("Max number is: ",number2)
> >
> > else:
> >  print("Max number is: ",number3)
> >
> > Try to insert numbers 3, 2 and 1 and the result will be number 3 and 1,
> > can you help me to fix it?! :\
> >
> > ^Bart

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

This looks like homework.  What you are asking could be solved a
number of ways.  I'm guessing your homework wants you to learn about
if/else and comparison operators.  At any rate, try the python tutor
forum, and be more specific to the rules of your assignment

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Type hinting of Python is just a toy ?

2019-01-04 Thread Joel Goldstick
On Fri, Jan 4, 2019 at 7:50 AM Chris Angelico  wrote:
>
> On Fri, Jan 4, 2019 at 8:06 PM iamybj--- via Python-list
>  wrote:
> >
> > In fact, there is only 3 types in all prigramming languages.
> > Primitive type: int, string, bool, char
> > Complex type: struct or class
> > Array Type: int[10], string[100], struct[1000]
> >
> > These 3 type can represent all thins in the world.
>
> Why do you need three types? REXX has just one type: the string.
> Structures, classes, arrays, mappings, etc are all implemented with a
> special type of variable, the "stem".
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list

I don't normally comment on this type of thread, but I believe the OP
is showing an example of the dunning-kruger effect
https://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect

Not teasing, really.

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to match list members in py3.x

2018-11-25 Thread Joel Goldstick
On Sun, Nov 25, 2018 at 11:51 AM Muhammad Rizwan
 wrote:
>
> On Sunday, 25 November 2018 11:41:56 UTC-5, Joel Goldstick  wrote:
> > On Sun, Nov 25, 2018 at 11:36 AM Muhammad Rizwan
> > <> wrote:
> > >
> > > IF YOU CAN'T HELP BETTER IGNORE THE POST AND DON'T TRY TO BE A SMART ASS.
> > >
> > >
> > > --
> > > https://mail.python.org/mailman/listinfo/python-list
> >
> > That isn't a productive way to get assistance.   It is true that
> > people here are often very knowledgeable to help with python problems,
> > but as a rule,  doing someone's homework isn't something people like
> > to do.
> >
> > On to your problem.  You should understand lists and sets, and for
> > loops.  Try some code and come back with what you have.  Then you will
> > get help to go further
> >
> > --
> > Joel Goldstick
> > http://joelgoldstick.com/blog
> > http://cc-baseballstats.info/stats/birthdays
>
> I have been trying since morning but it doesn't work.

The way to use this mailing list is to explain your problem, which you
have done.  Then, show the code you have written with the results it
produces.  Its good to include the operating system you are using
(windows, linux, osx), and if your code produces a traceback, copy and
paste it here.

Its common to be frustrated learning to write and writing code, but if
you want help you have to show something for others to help you with
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to match list members in py3.x

2018-11-25 Thread Joel Goldstick
On Sun, Nov 25, 2018 at 11:36 AM Muhammad Rizwan
 wrote:
>
> IF YOU CAN'T HELP BETTER IGNORE THE POST AND DON'T TRY TO BE A SMART ASS.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list

That isn't a productive way to get assistance.   It is true that
people here are often very knowledgeable to help with python problems,
but as a rule,  doing someone's homework isn't something people like
to do.

On to your problem.  You should understand lists and sets, and for
loops.  Try some code and come back with what you have.  Then you will
get help to go further

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Error in installing "pyperclip" module

2018-11-10 Thread Joel Goldstick
On Sat, Nov 10, 2018 at 12:29 PM boB Stepp  wrote:
>
> Greetings Hemant!
>
> On Sat, Nov 10, 2018 at 10:31 AM Hemant Chauhan
>  wrote:
> >
> > Hi team,
> > I’m having trouble in installing pyperclip  module through command line.
> > I just upgraded to the latest version.
> > Here’s the SS of command line showing error.
>
> Unfortunately this is a text only mailing list, which disallows
> attachments.

One maybe small quibble.  I don't think it is unfortunate at all that
this mailing list is text only.  Coding is text.  It is not screen
shots.  If a questioner is first thinking of pasting screen shots or
attaching files to a mailing list like this, they should be informed
what a useless method this is, and how they can provide information
that is useful, and that can help others help them.  This is what this
response does.  So, I don't mean to be snarky

So no one will see your screenshot.  Instead you should
> copy and paste into a *plain text* email what you entered on the
> command line and likewise copy and paste the resulting error messages
> into the email.  Please state your operating system and version of
> Python that you are using.  With that information I am sure someone
> here will be able to help you.
>
> > P.S. – I’m a beginner in Python , it’s the first programming language I 
> > started with.
>
> If you are just starting out, a better forum for a new learner to
> programming and Python would be the Python Tutor mailing list.
> Subscription information can be found at
> https://mail.python.org/mailman/listinfo/tutor  However, people on the
> this main list are quite friendly and helpful to newbies as well.  In
> fact many here actively monitor and help out on the Tutor list.
> --
> boB
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why list.reverse() modifies the list, but name.replace() does not

2018-09-05 Thread Joel Goldstick
On Mon, Sep 3, 2018 at 1:50 PM C W  wrote:
>
> Hello all,
>
> I am learning the basics of Python. How do I know when a method modifies
> the original object, when it does not. I have to exmaples:
> Example 1:
> > L = [3, 6, 1,4]
> > L.reverse()
> > L
> [4, 1, 6, 3]
> This changes the original list.
>
> Example 2:
> > name = "John Smith"
> > name.replace("J", j")
> > name
> 'John Smith'
> This does not change the original string.
>
> Why the two examples produce different results? As a beginner, I find this
> confusing. How do you do it?
>
> Thank you!
> --
> https://mail.python.org/mailman/listinfo/python-list

Learn about help.  Go to python command line and type help(L) it will show that
 this method reverses in place.  Type help(name) and it will show that this
method returns the result, but does not change your list.

--
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays

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


Re: Why list.reverse() modifies the list, but name.replace() does not modify the string?

2018-09-03 Thread Joel Goldstick
On Mon, Sep 3, 2018 at 1:50 PM C W  wrote:
>
> Hello all,
>
> I am learning the basics of Python. How do I know when a method modifies
> the original object, when it does not. I have to exmaples:
> Example 1:
> > L = [3, 6, 1,4]
> > L.reverse()
> > L
> [4, 1, 6, 3]
> This changes the original list.
>
> Example 2:
> > name = "John Smith"
> > name.replace("J", j")
> > name
> 'John Smith'
> This does not change the original string.
>
> Why the two examples produce different results? As a beginner, I find this
> confusing. How do you do it?
>
> Thank you!
> --
> https://mail.python.org/mailman/listinfo/python-list

Learn about help.  Go to python command line and type help(L) it will
show that this method reverses in place.  Type help(name) and it will
show that this method returns the result, but does not change your
list.

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help Needed : script weird result.

2018-09-01 Thread Joel Goldstick
On Sat, Sep 1, 2018 at 1:26 PM duncan smith  wrote:
>
> On 01/09/18 18:11, moha...@gmail.com wrote:
> > All,
> >
> > I m trying to run this small script to find the lowest of the given array 
> > of numbers. The script works fine for various combination of inputs but 
> > fails in a weird way for a particular set of inputs, can anyone point the 
> > mistake in the script and the behavior.
> >
> > Script
> >
> > x = input ("Enter the numbers separated by space and press ENTER :")
> > x = x.split(" ")
> >
> > def checkmin(arr):
> > lowest = arr[0]
> > for count in range(0,len(arr),1):
> > if arr[count] < lowest :
> > lowest = arr[count]
> > else :
> > pass
> > print (lowest)
> > return lowest
> >
> > minimum = checkmin(x)
> > print ("Lowest : {0}".format (minimum))
> >
> >
> > Weird output is as below.
> >
> > == RESTART: C:\Users\mohan\Desktop\temp.py 
> > ==
> > Enter the numbers separated by space and press ENTER :5 90 63 82 59 24
> > 5
> > 5
> > 5
> > 5
> > 5
> > 24
> > Lowest : 24
> >
> > Regards
> > Mohan C
> >
>
>
> Compare,
>
> >>> min(5, 90, 63, 82, 59, 24)
> 5
> >>> min('5', '90', '63', '82', '59', '24')
> '24'
> >>>
>
> Duncan
> --
> https://mail.python.org/mailman/listinfo/python-list

integers are not strings.  Strings collate according to alphanumeric
sequence.  So the 2 in 24 makes it less than the 5


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Connection refused when tryign to run bottle/flask web framweworks

2018-08-21 Thread Joel Goldstick
On Tue, Aug 21, 2018 at 12:06 PM Dennis Lee Bieber
 wrote:
>
> On Mon, 20 Aug 2018 05:07:59 -0700 (PDT), ?
>  declaimed the following:
>
> >?? ???, 20 ? 2018 - 7:59:06 ?.?. UTC+3, ? ??? dieter ??:
> >> ?  writes:
>
> >> >
> >> > run(host='localhost', port=8080)
> >>
> >> Likely, the code above is supposed to start the server component.
> >> Ensure, that the start is successful (I typically use "lsof -i"
> >> to find out whether a server is listening on the expected port).
> >
> >Iam trying to access the bottle web framework running on my VPS as
> >
> >http://superhost.gr:8080/hello
> >
> >i get connection refused
>
> Note that the coded snippet says LOCALHOST... It is NOT listening for
> connections coming from anything except 127.0.0.1!
>
> >
> >[root@superhost public_html]# python3 app.py
> >Bottle v0.12.13 server starting up (using WSGIRefServer())...
> >Listening on http://localhost:8080/
> >Hit Ctrl-C to quit.
> >
> >So, i wonder why the socket with port 8080 aint being displayed.
>
> Same... it is configured to only listen to connections from the same
> (virtual?) machine on which it is running.
>
> C:\Users\Wulfraed>nslookup superhost.gr
> Server:  dsldevice6.attlocal.net
> Address:  2600:1700:e630:890::1
>
> Non-authoritative answer:
> Name:superhost.gr
> Address:  176.223.129.220
>
>
> C:\Users\Wulfraed>
>
>
> Obviously "superhost.gr" @ 176.223.129.220 is NOT the same as
> "localhost" at 127.0.0.1
>
>
>
> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> https://mail.python.org/mailman/listinfo/python-list
although i don't offer advice too often here, as i am kind of
retired., this is extremely reminiscent of a whole lot of server issue
posts from I believe this same OP some years ago.  It will soon become
a rabbit hole.  take care to get involved.  I believe then he was
nikos cranus or something that translated into metal head in english.


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: printing to stdout

2018-08-19 Thread Joel Goldstick
On Sun, Aug 19, 2018 at 12:16 PM Richard Lucassen
 wrote:
>
> On Sun, 19 Aug 2018 10:11:08 -0400
> Joel Goldstick  wrote:
>
> > > Well, apparently there were quite a lot of things that makes the
> > > code more readable I'd say. And even better. But it was indeed not
> > > very unPythony. OTOH, I'm not a programmer, otherwise I would have
> > > written this in C ;-)
> >
> > This strikes me as an odd conclusion.  Raspberry Pi places a strong
> > emphasis on python.  It certainly doesn't execute as fast as C can,
> > but it provides a conceptually higher level programming model.  There
> > is extremely good community support for python with Pi (a huge plus),
> > and the code is much more understandable.  It is faster to write code
> > with python, you can come back to it and understand it more readily at
> > some later time, as can others.  And it runs 'fast enough' .  So, no,
> > I don't think if you were a 'programmer' you would have used C to do
> > this project.  But others may be of a different persuation.
>
> You've got absolutely a point that Python seems to be largely supported
> for Rpi. But I'll tell you something else: I just started to use a
> Rpi ;-) I agree that python code is much more understandable than C.
>
> > You seemed to have snipped your question about zip function.  It takes
> > iterables (things like lists, tuples, dictionaries) as arguments and
> > pairs them together to form tuples.  Look it up.  Very useful.  As and
> > example, if you have list1 = (1,2,3), and list2 = (4,5,6,7) and zip
> > them you will get ((1,4), (2,5),(3,6)).  (It stops when the shortest
> > iterable is exhausted)
> >
> > Your allusion to pointers is misguided.  Python is not like C or
> > assembler.  You don't, and don't need to know where objects are
> > stored.  Names are assigned to reference data objects
>
> I'll have another look at it, I was just searching for a clear
> explanation, but the page I found was not clear enough for me. I'll
> have to take some time for it...

try python.org tutorial, and search for terms like names, or name
binding.  And also 'namespace'

> --
> Richard Lucassen
> http://contact.xaq.nl/
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: printing to stdout

2018-08-19 Thread Joel Goldstick
On Sun, Aug 19, 2018 at 9:56 AM richard lucassen
 wrote:
>
> On Sun, 19 Aug 2018 12:02:51 +0300
> Marko Rauhamaa  wrote:
>
> > richard lucassen :
> > > As I'm new to Python, just this question: are there any unPythony
> > > things in this code?
> >
> > Your code looks neat.
>
> Well, apparently there were quite a lot of things that makes the code
> more readable I'd say. And even better. But it was indeed not very
> unPythony. OTOH, I'm not a programmer, otherwise I would have written
> this in C ;-)

This strikes me as an odd conclusion.  Raspberry Pi places a strong
emphasis on python.  It certainly doesn't execute as fast as C can,
but it provides a conceptually higher level programming model.  There
is extremely good community support for python with Pi (a huge plus),
and the code is much more understandable.  It is faster to write code
with python, you can come back to it and understand it more readily at
some later time, as can others.  And it runs 'fast enough' .  So, no,
I don't think if you were a 'programmer' you would have used C to do
this project.  But others may be of a different persuation.

>
> R.

You seemed to have snipped your question about zip function.  It takes
iterables (things like lists, tuples, dictionaries) as arguments and
pairs them together to form tuples.  Look it up.  Very useful.  As and
example, if you have list1 = (1,2,3), and list2 = (4,5,6,7) and zip
them you will get ((1,4), (2,5),(3,6)).  (It stops when the shortest
iterable is exhausted)

Your allusion to pointers is misguided.  Python is not like C or
assembler.  You don't, and don't need to know where objects are
stored.  Names are assigned to reference data objects
>
> --
> richard lucassen
> http://contact.xaq.nl/
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Program to output a subset of the composite numbers

2018-08-15 Thread Joel Goldstick
On Wed, Aug 15, 2018 at 8:36 AM  wrote:
>
> I am not terribly familiar with Python, but am currently authoring an integer 
> sequence for www.oeis.org and was wondering if anyone in the community could 
> help me with authoring a Python program that outputs, "Composite numbers that 
> are one less than a composite number."
>
> Thanks!
> Musatov
> --
> https://mail.python.org/mailman/listinfo/python-list

Since composite numbers are all the positive integers that are not
prime and not one, I believe you can find code to produce a sequence
of prime numbers, and you can subtract that sequence from the sequence
of positive integers

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: about main()

2018-07-05 Thread Joel Goldstick
On Thu, Jul 5, 2018 at 7:45 AM, Abdur-Rahmaan Janhangeer
 wrote:
> performance?

You are asking basic file layout questions in the learning process of
understand how to code in python.  Performance should be very low on
your list of concerns.  The only thing that happens when the file is
loaded is that it gets compiled, and run.  If it is imported, and you
have the 'if __name__ ... block, it will run the code within the if
block.  If that has a main() function it makes it simpler later to
change what main does instead of cluttering up the if block.  But
there is no 'performance' issue that I can see.
>
> Abdur-Rahmaan Janhangeer
> https://github.com/Abdur-rahmaanJ
>
> * Create as many functions as you can
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Understanding memory location of Python variables

2018-06-16 Thread Joel Goldstick
On Sat, Jun 16, 2018 at 12:38 PM,   wrote:
> Hi everyone,
>
> I'm intrigued by the output of the following code, which was totally contrary 
> to my expectations. Can someone tell me what is happening?
>
>>>> myName = "Kevin"
>>>> id(myName)
> 47406848
>>>> id(myName[0])
> 36308576
>>>> id(myName[1])
> 2476000
>
> I expected myName[0] to be located at the same memory location as the myName 
> variable itself. I also expected myName[1] to be located immediately after 
> myName[0].
> --
> https://mail.python.org/mailman/listinfo/python-list

Others can probably give a more complete explanation, but small
numbers, and apparently letters are cached since they are so common.

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: stock quotes off the web, py style

2018-05-16 Thread Joel Goldstick
On Wed, May 16, 2018 at 8:33 AM, Friedrich Rentsch
<anthra.nor...@bluewin.ch> wrote:
>
>
> On 05/16/2018 02:23 AM, Mike McClain wrote:
>>
>>  Initially I got my quotes from a broker daily to plug into a
>> spreadsheet, Then I found Yahoo and wrote a perl script to grab them.
>> When Yahoo quit supplying quotes I found AlphaVantage.co and rewrote
>> the perl script.
>>  AlphaVantage.co has been down since last week and I found
>> iextrading.com has a freely available interface. Since it needs
>> a rewrite and I'm trying to get a handle on python this seems
>> like a good opportunity to explore.
>>  If someone would please suggest modules to explore. Are there any
>> upper level modules that would allow me to do something like:
>>
>> from module import get
>> def getAquote(symbol):
>>  url = 'https://api.iextrading.com/1.0/stock/()/quote'.format(symbol)
>>  reply = module.get(url)
>>  return my_parse(reply)
>>
>> Thanks,
>> Mike
>> --
>> Men occasionally stumble over the truth, but most of them pick
>> themselves up and hurry off as if nothing ever happened.
>>  - Churchill
>
>
> I didn't know the site you mention. I've been getting quotes from Yahoo
> daily. The service they discontinued was for up to 50 symbols per page. I
> now parse a separate page of some 500K of html for each symbol! This site is
> certainly more concise and surely a lot faster. It serves a naked set of
> data, which happens to conform to the python source code specification for
> dictionaries and consequently can be compiled into a dictionary with 'eval',
> like so:
>
>>>> ibm = urllib2.urlopen
>>>> ("https://api.iextrading.com/1.0/stock/IBM/quote;).read()
>>>> ibm = eval (ibm)
>>>> for item in sorted (ibm.items()): print '%-24s%s' % item
>
> avgTotalVolume  5331869
> calculationPriceclose
> change  -0.56
> changePercent   -0.00388
> close   143.74
> closeTime   1526414517398
> companyName International Business Machines Corporation
> delayedPrice143.74
> delayedPriceTime1526414517398
> high143.99
> iexAskPrice 0
> iexAskSize  0
> iexBidPrice 0
> iexBidSize  0
> iexLastUpdated  0
> iexMarketPercent0
> iexRealtimePrice0
> iexRealtimeSize 0
> iexVolume   0
> latestPrice 143.74
> latestSourceClose
> latestTime  May 15, 2018
> latestUpdate1526414517398
> latestVolume4085996
> low 142.92
> marketCap   131948764304
> open143.5
> openTime1526391000646
> peRatio 10.34
> previousClose   144.3
> primaryExchange New York Stock Exchange
> sector  Technology
> symbol  IBM
> week52High  171.13
> week52Low   139.13
> ytdChange   -0.0485148849103
>
> You would do multiple symbols in a loop which you enter with an open urllib
> object, rather than opening a new one for each symbol inside the loop.
>
> Frederic
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Many people find the library called Requests a better alternative to
urllib.  It is more intuitive

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: syntax error (?) on ubuntu

2018-05-03 Thread Joel Goldstick
On Thu, May 3, 2018 at 9:06 AM, joseph pareti <joeparet...@gmail.com> wrote:
> $ python tf_simple.py
>
> /anaconda/envs/py35/lib/python3.5/site-packages/h5py/__init__.py:36:
> FutureWarning: Conversion of the second argument of issubdtype from `float`
> to `np.floating` is deprecated. In future, it will be treated as
> `np.float64 == np.dtype(float).type`.
>   from ._conv import register_converters as _register_converters
> Traceback (most recent call last):
>   File "tf_simple.py", line 29, in 
> import uniio
>   File "../tools/uniio.py", line 132
> if(PY3K): ID = ID.decode("utf-8")
>  ^
> TabError: inconsistent use of tabs and spaces in indentation
> --
> https://mail.python.org/mailman/listinfo/python-list

Check to see if you have a tab after the colon in the last line.  You
must use colons or spaces, but not both

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Looking for advice

2018-04-20 Thread Joel Goldstick
On Fri, Apr 20, 2018 at 1:28 PM, 20/20 Lab <l...@2020fresno.com> wrote:
> Going to write my first python program that uses a database. Going to store
> 50-100 rows with 5-10 columns.  Which database / module would you advise me
> to use?  It's basically going to be processing order status emails for the
> sales staff.  Producing a webpage (2-3 times daily, as updates arrive) that
> has the sales staff orders and status on it.   I'm thinking just a simple
> sqlite, but dont want to waste time going down the wrong path.
>
>
> Thank you for your time
>
> --
> https://mail.python.org/mailman/listinfo/python-list

sqlite is a small, in memory db that comes standard with python (i'm
pretty sure).  Great place to start

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for info

2018-01-31 Thread Joel Goldstick
On Wed, Jan 31, 2018 at 10:55 AM, <harnal...@gmail.com> wrote:

> from where we learn python for free of cost. i am begineer in python.plzz
> help me
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Start with python.org tutorial pages

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to use a regexp here

2017-12-08 Thread Joel Goldstick
On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder <n...@nedbatchelder.com> wrote:

> On 12/4/17 4:36 AM, Cecil Westerhof wrote:
>
>> I have a script that was running perfectly for some time. It uses:
>>  array = [elem for elem in output if 'CPU_TEMP' in elem]
>>
>> But because output has changed, I have to check for CPU_TEMP at the
>> beginning of the line. What would be the best way to implement this?
>>
>>
> No need for a regex just yet:
>
> array = [elem for elem in output if elem.startswith('CPU_TEMP')]
>
> (btw, note that the result of this expression is a list, not an array, for
> future Googling.)
>
> --Ned.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

I like Ned's clear answer, but I'm wondering why the original code would fail
because the substring is at the start of the line, since '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

--
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays

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


Re: Python script

2017-12-07 Thread Joel Goldstick
On Thu, Dec 7, 2017 at 9:06 AM, <prvn.m...@gmail.com> wrote:

> Hi All,
> I am new to python need help to write a script in python
> my requirement is :-
> write a python script to print sentence from a txt file to another txt file
>
> Regards,
> Praveen
> --
> https://mail.python.org/mailman/listinfo/python-list
>

So, the way it works here is that you should write some code as best you
can.  Paste it into your question using plaintext so that the formatting
remains as coded, and tell us what errors you get (copy the traceback).
People won't write code for you here, but they will help you figure out
what you don't understand

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: we want python software

2017-12-05 Thread Joel Goldstick
Go visit python.org to see how to download python for the operating system
you are using.  Its free of course

On Tue, Dec 5, 2017 at 11:55 AM, Igor Korot <ikoro...@gmail.com> wrote:

> Hi,
>
> On Tue, Dec 5, 2017 at 9:10 AM, Jyothiswaroop Reddy
> <jyothiswaroopreddy9...@gmail.com> wrote:
> > Sir,
> > I am b.tech student I would like to learn python. So please send
> the python software.
>
> Sorry, we don't send anything. You will have to go get it yourself. -)
>
> Thanking you back.
>
> > Thanking you sir.
> >
> > Sent from Mail for Windows 10
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to use a regexp here

2017-12-04 Thread Joel Goldstick
On Mon, Dec 4, 2017 at 5:21 AM, Ned Batchelder <n...@nedbatchelder.com>
wrote:

> On 12/4/17 4:36 AM, Cecil Westerhof wrote:
>
>> I have a script that was running perfectly for some time. It uses:
>>  array = [elem for elem in output if 'CPU_TEMP' in elem]
>>
>> But because output has changed, I have to check for CPU_TEMP at the
>> beginning of the line. What would be the best way to implement this?
>>
>>
> No need for a regex just yet:
>
> array = [elem for elem in output if elem.startswith('CPU_TEMP')]
>
> (btw, note that the result of this expression is a list, not an array, for
> future Googling.)
>
> --Ned.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

I like Ned's clear answer, but I'm wondering why the original code would
fail because the substring is at the start of the line, since '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

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Boolean Expressions

2017-09-28 Thread Joel Goldstick
On Wed, Sep 27, 2017 at 5:21 AM, Cai Gengyang <gengyang...@gmail.com> wrote:

> On Wednesday, September 27, 2017 at 1:01:50 PM UTC+8, Cameron Simpson
> wrote:
> > On 26Sep2017 20:55, Cai Gengyang <gengyang...@gmail.com> wrote:
> > >On Wednesday, September 27, 2017 at 6:45:00 AM UTC+8, Cameron Simpson
> wrote:
> > >> On 26Sep2017 14:43, Cai Gengyang <gengyang...@gmail.com> wrote:
> > >> >C) Set bool_three equal to the result of
> > >> >19 % 4 != 300 / 10 / 10 and False
> > >> >
> > >> 19 % 4 = 3 which is equal to 300 / 10 / 10 = 3, hence the first term
> is
> > >> False. Entire expression is then equal to True, because False and
> False =
> > >> True
> > >>
> > >> Entire expression is False because the left hand side is False.
> > >
> > >Am I missing something here ? 19 % 4 = 19 modulo 4 equals to 3 right ?
> which
> > >equals the right hand side , hence first term is True
> >
> > But the test is for "!=", not "==". So False.
> >
> > Cheers,
> > Cameron Simpson <c...@cskk.id.au> (formerly c...@zip.com.au)
>
> Right ... I didn't see the ' =! '
> --
>

You didn't see the '!='


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A small quiz question

2017-08-16 Thread Joel Goldstick
On Wed, Aug 16, 2017 at 7:06 AM, Stefan Ram <r...@zedat.fu-berlin.de> wrote:

>   I wrote my first Python quiz question!
>
>   It goes like this:
>
>   Can you predict (without trying it out) what the Python
>   console will output after the following three lines have
>   been entered?
>
> def f(i): print(i); return i;
>
> f(4)**f(1)**f(2)
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

That's a nice problem for order evaluation.  I guessed wrong.

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Redirecting input of IDLE window

2017-08-14 Thread Joel Goldstick
On Mon, Aug 14, 2017 at 4:47 AM, Friedrich Rentsch <anthra.nor...@bluewin.ch
> wrote:

> Hi,
>
> I work interactively in an IDLE window most of the time and find "help
> (...)" very useful to summarize things. The display comes up directly
> (doesn't return a text, which I could edit, assign or store). I suspect
> that there are ways to redirect the display, say to a file. Thanks for
> suggestions.
>
>
> Frederic
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

do you know about the utility called pydoc?  Type it at a command line to
learn more.  It displays information like help does in a python
environment, but you can also redirect it to a file

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need python script to get last 6 month's monthly billing

2017-08-08 Thread Joel Goldstick
On Tue, Aug 8, 2017 at 6:18 AM, <sandeep.gk...@gmail.com> wrote:

> Hi,
>
>
> I would like to create AWS monthly billing graph using python and python
> flask.so for this i need python script using that i have to get last 6
> month's monthly bill in AWS.
> for this, i have created one virtual environment in my local machine. for
> examplle my ip is: 127.0.0.0:5000.
> Here after pull that script, it's automatically connected to AWS and
> display's last 6 month's data. its my requirement.
>
> Thanks in advance.
>
> Thank you,
> Sandeep
> --
> https://mail.python.org/mailman/listinfo/python-list
>

You haven't asked a question.  It is doubtful someone here would write code
for you.  In any case your problem isn't well stated.  Why don't you show
the code you have written, and explain where it fails?

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: In which order many functions are executed in a python code

2017-06-09 Thread Joel Goldstick
On Fri, Jun 9, 2017 at 2:46 PM, Thomas Nyberg <tomuxi...@gmx.com> wrote:
> On 06/09/2017 11:39 AM, sondes kalboussi wrote:
>>
>> Am a bit confused I was thinking that the order of execution of functions in 
>> a code is from the first to the last function but sometimes it is the 
>> opposite, for instance, some parameters or outputs from the second function 
>> are called in the first one even thou they are not global, any hints ?
>>
> Maybe if you post some specific code it will be easier to see what

Functions are run in the order in which they are called from the main code
-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I need help with making my claculator

2017-05-20 Thread Joel Goldstick
On Sat, May 20, 2017 at 9:49 AM, Steve D'Aprano
<steve+pyt...@pearwood.info> wrote:
> On Sat, 20 May 2017 09:13 pm, bartc wrote:
>
>> On 20/05/2017 03:10, Chris Angelico wrote:
>>> Without any specific questions, you're not going to get anything more
>>> than a basic eyeballing of the code.
>>
>> Try running the program.
>>
>> (I did that but I can't follow this style of coding so can't help.)
>
> Chris is within his rights to refuse to run untrusted code downloaded over
> the internet.
>
> It's not even the security aspect: the code is fairly short, and doesn't
> appear to be obfuscated or do anything nasty.
>
> But its a matter of fairness: we're volunteers, not slaves or paid workers,
> and we get to choose on what problems we work on.
>
> We're not being paid to solve people's problems, we're doing it from a sense
> of community (and maybe to show off, a bit). We've only got so much time
> and energy for solving people's problems, and the more vague those problems
> are, the less likely we are to care enough to put the work in to solve it.
>
> Give us an interesting problem, and some of us will put *hours* of work into
> it. But give us something vague or boring or trivial, and What's In It For
> Us?
>
> The Original Poster garsink at gmail.com cares so little for our time that
> he or she didn't even *ask* a question. Or give a name we can call them
> (email addresses are so impersonal and unfriendly). Nothing but a pair of
> statements: I need help, here's my code.
>
> Well, we all need help, and thank you for sharing.
>
> Why should we bother to run your code if you can't even be bothered to say
> Please or Thank You or tell us what's wrong with it?
>
> "garsink", or whatever you would like us to call you, please help us to help
> you. Don't expect us to run your code until you've made it interesting for
> us. Please read this webpage before answering:
>
> http://sscce.org/
>
> It is written for Java programmers, but it applies to Python too.
>
> Thank you.
>
>
>
> --
> Steve
> Emoji: a small, fuzzy, indistinct picture used to replace a clear and
> perfectly comprehensible word.
>
> --
> https://mail.python.org/mailman/listinfo/python-list

I took a look at the url from the email address.  Its some private
school for apparently youngish kids.  So, a little perspective on the
rather vague query.

Poster, maybe try the python-tutor mailing list

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I have a encountered a new problem.

2017-05-01 Thread Joel Goldstick
On Mon, May 1, 2017 at 7:19 AM, SUMIT SUMAN <sumitsuman6...@gmail.com> wrote:
> I have encountered a problem while opening the Python 3.6.1 IDLE
>
>
> The error message is this-
>
> [image: Inline image 1]
> --
> https://mail.python.org/mailman/listinfo/python-list

you need to cut and paste the traceback -- most people (all?) won't
see the image you added here

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Bigotry and hate speech on the python mailing list

2017-04-18 Thread Joel Goldstick
On Tue, Apr 18, 2017 at 5:30 AM, James McMahon <jsmcmah...@gmail.com> wrote:
> Can the moderators please get involved here and remind people to address
> python related topics and questions on the python mailing list? While I can
> only speak to my interest when joining this list, isn't python why
> most people joined this list? Others have different and polarizing views on
> many subjects. This just isn't the right place to voice your views on
> subjects other than python. I delete this same tired thread every day, and
> every day it reappears. With all manners and due respect, stay on topic.
>
> Isn't this list content moderated by anyone?
>
> -Jim
>

Plus 1 to Jim.  Come on gang! Back to python!  Spaces vs. tabs anyone?



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Quick questions about globals and database connections

2017-04-05 Thread Joel Goldstick
On Wed, Apr 5, 2017 at 11:09 AM, Python <python@example.invalid> wrote:
> Le 05/04/2017 à 16:54, DFS a écrit :
>>
>> I have identical databases in sqlite and postgres.  I want to run the
>> same code against them, but am having a small issue.
>>
>> Current code below throws the dreaded:
>>
>> NameError: global name 'db' is not defined
>>
>> on line 12
>>
>> How do I fix it?  I want to keep dbconnect() as a separate function.
>>
>> Thanks.
>>
>> -
>> 1 import sqlite3, psycopg2
>> 2
>> 3 def dbconnect(dbtype):
>> 4   if dbtype == "sqlite":
>> 5 conn = sqlite3.connect(cstr)
>> 6   elif dbtype == "postgres":
>> 7 conn = psycopg2.connect(cstr)
>
>
> 8   return conn.cursor()
>
>> 9
>> 10 def updatedb(dbtype):
>
>
> 11   db = dbconnect(dbtype)
>
>> 12   db.execute("DML code")
>> 13   print "updated " + dbtype
>> 14   'close connection
>>
>> 15 def main():
>> 16   updatedb('sqlite')
>> 17   updatedb('postgres')
>> 18
>> 19 if __name__ == "__main__":
>> 20   main()
>> -
>>
>>
>
> --
> https://mail.python.org/mailman/listinfo/python-list

You may have an indentation problem that isn't apparent in your code
pasted here.  Are you sure that dbconnect always returns something?

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Escaping confusion with Python 3 + MySQL

2017-03-26 Thread Joel Goldstick
On Sun, Mar 26, 2017 at 11:48 AM, Νίκος Βέργος <me.on@gmail.com> wrote:
> Τη Κυριακή, 26 Μαρτίου 2017 - 6:39:01 μ.μ. UTC+3, ο χρήστης Steve D'Aprano 
> έγραψε:
>> On Mon, 27 Mar 2017 02:11 am, Νίκος Βέργος wrote:
>>
>> > I just tried:
>> >
>> > domain = '.'.join( host.split('.')[-2:] )
>> > domain = '%' + domain + '%'
>> >
>> > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros,
>> > browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s"
>> > ''', (pID, domain, ref, location, useros, browser, lastvisit, domain) )
>> >
>> > and i received no error in the error_log but
>> > ProgrammingError(1064, "You have an error in your SQL syntax; check the
>> > manual that corresponds to your MariaDB server version for the right
>> > syntax to use near '(pagesID, host, ref, location, useros, browser,
>> > visits) VALUES (1, '%cyta.gr%', ' at line 1")
>>
>> Start by following the instructions given:
>>
>> check the manual that corresponds to your MariaDB server version
>> for the right syntax to use
>>
>> just like the error message tells you to do.
>>
>> Are you sure that the domain needs to have leading and trailing percentage
>> signs? "%cyta.gr%" instead of "cyta.gr"?
>>
>> Are you sure that the LIKE clause needs double quotes?
>>
>> LIKE "%s"
>>
>> Perhaps MariaDB requires single quotes:
>>
>> LIKE '%s'
>>
>> or perhaps no quotes at all:
>>
>> LIKE %s
>>
>>
>> But I'm just guessing, because I haven't read the MariaDB manual. You should
>> do so.
>>
>>
>> > which you can see at http://superhost.gr
>>
>> Ah, Nikos, its been a long time! I thought I recognised your style of
>> posting.

Not long enough!
>
>
> Howdy Steve!
> Yes its me and yes its have been a long time! How are you?!
>
> Yeap still trying to make my webiste better and better every day.
>
> As for MariaDB i tried with single/double/no_quoting at all and it still 
> produces
> ProgrammingError(1064, "You have an error in your SQL syntax; check the 
> manual that corresponds to your MariaDB server version for the right syntax 
> to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES 
> (1, 'cyta.gr', '' at line 1")
>
> I think that Ian Kelly is right and it has soemthign to do with the databse 
> wrapper not substituting properly the actual string contain in the LIKE 
> clause between the double quotes.
>
> Perhaps i need to change pymysql with some other database interface or there 
> is something other than that?
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEOPLE! PLEASE! [ WAS: Re: Who are the "spacists"? ]

2017-03-25 Thread Joel Goldstick
On Sat, Mar 25, 2017 at 3:40 PM, Gilmeh Serda
<gilmeh.ser...@nothing.here.invalid> wrote:
>
>>> So Python supports both spaces and tabs for indentation.
>
> People!
>
> This is as far from normal conversation about Python as it gets!
>
> Keep this shit to yourselves, PLEASE!
>
> Using an editor worth the name, makes it a non issue (since it can
> convert between one and the other, Eclipse/LiClipse comes to mind). Get
> real, and think before you post/send!
>
> --
> Gilmeh
> --
> https://mail.python.org/mailman/listinfo/python-list

+1


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Who are the "spacists"?

2017-03-20 Thread Joel Goldstick
On Mon, Mar 20, 2017 at 1:39 PM, Steve D'Aprano
<steve+pyt...@pearwood.info> wrote:
> On Tue, 21 Mar 2017 02:40 am, Tobiah wrote:
>
>>> I wonder whether the tabs versus spaces divide is closely aligned to the
>>> Windows versus Unix/Linux divide?
>>>
>>> It seems to me that Unix users are typically going to be using Unix tools
>>> which often assume spaces are used for indentation, and consequently cope
>>> badly with tabs.
>>
>> I can't think of any classic Unix tool that behaves in a way that would
>> support this point of view.
>
> And yet I'm forever being told by my Linux sys admin work mates "don't use
> tabs, because they break everything". For another example, see JMZ's essay
> (its already been linked to twice in this thread, look it up).
>
> We've had a similar attitude right here from Marko, who insists that
> anything except 8-column tabs is the Devil's Work. (Or something like
> that -- to be perfectly honest, I'm not really sure I understand *what*
> Marko's objection is.)
>
> So okay, if tabs work fine with Unix tools, why do so many Unix people avoid
> tabs as if they were radioactive plague?
>
>
>
>
> --
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.
>
> --
> https://mail.python.org/mailman/listinfo/python-list

I was the first to post that this topic would go nowhere.  77 posts
later, for some reason the word 'spaceist' bothers me.  Why do people
debate spaces versus tabs?  I don't think it has to do with spaces or
tabs, but something more sociological or psychological.

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Who are the "spacists"?

2017-03-17 Thread Joel Goldstick
On Fri, Mar 17, 2017 at 8:52 PM, Mikhail V <mikhail...@gmail.com> wrote:
> So Python supports both spaces and tabs for indentation.
>
> I just wonder, why not forbid spaces in the beginning of lines?
> How would one come to the idea to use spaces for indentation at all?
>
> Space is not even a control/format character, but a word separator.
> And when editors will be proportional font based, indenting with
> spaces will not make *any* sense so they are just annoyance.
> Neither makes it sense in general case of text editing.
> I think it would be a salvation to forbid spaces for indentation,
> did such attemps take place?
> --
> https://mail.python.org/mailman/listinfo/python-list

This is not a useful conversation.  It has been had over and over in
the past.  Some people like tabs, some like spaces.  In python you can
use either, but you must stick to one or the other


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problems with scripts

2017-02-13 Thread Joel Goldstick
On Mon, Feb 13, 2017 at 11:30 AM,  <lauren.sophia1...@gmail.com> wrote:
> Hello! I have 2 python assignments that I just can't figure out. The first 
> one returns the same thing no matter what I input and the second won't accept 
> "done" to stop the program and return answers. Please help!
>
> 1)
> print("How old are you: 17, 18, 19, or 20?")
> answer = input("> ")
> if answer == 17 or 18 or 19 or 20:

You can't do if like you are trying to do.  First, you are comparing
to numbers, but you have a string for answer.  So, convert answer to
an int, and then look up 'if answer in (17,18, etc.):

> print("Wow, you are old!")
> elif answer != 17 or 18 or 19 or 20:
> if type(answer) is int or float:
> print("You just can't follow drections, can you? Choose either 17, 
> 18, 19, or 20.")
> input("> ")
> elif type(answer) is str:
> print("That isn't even a number. Choose either 17, 18, 19, or 20.")
> input("> ")
>
>
>
> 2)
> print("This program keeps track of the prices of items and how many items 
> bought at that price. Enter 'done' to return the answers.")
> item_num = 1
> total_price = 0
> price = input("What is the price of item number " + str(item_num) + " ? ")
> total_items = 0
> how_many = input("How many items at that price? ")
> while price or how_many != "done":
> total_price = int(total_price) + int(price)
> total_items = int(total_items) + int(how_many)
> item_num = item_num + 1
> price = input("What is the price of item number " + str(item_num) + " ? ")
> how_many = input("How many items at that price? ")
>
> if input == done:
> print("The total price is $" + str(total_price) + ". And the number of 
> items for that price is " + str(total_items) + ".")
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Clickable hyperlinks

2017-01-09 Thread Joel Goldstick
On Mon, Jan 9, 2017 at 8:33 PM, Michael Torrie <torr...@gmail.com> wrote:
> On 01/09/2017 06:02 PM, Deborah Swanson wrote:
>> Fair enough. I only suggested that they could have started their own
>> thread, but mainly just to point out that they would have been off-topic
>> if they did. I didn't demand that they do so, I just wanted them to
>> think about it.
>
> I don't see how it would be any more off-topic than your original query.
> Which is to say, talking about Python's use of the console (beit a Win32
> Console API window, a terminal emulator, or a PyCharm window) is on-topic.
>
>> I also prefer a loosely controlled list, and a freewheeling list is
>> ideal, but it only works well if people exercise basic politeness and
>> common sense.
>
> I agree.  Be aware that your own posts in this thread have bordered on
> inflammatory on occasion.  Certainly your remark about "any educated
> person would know that" could be taken in a very negative way.  I can't
> remember everything I read in this thread, but I'm hard-pressed to find
> examples where people were not polite to you, even though you pressed on
> with certain lines of comment, especially when it was pointed out that
> your question came from the wrong premise and idea of what the "console"
> is.  I don't believe that someone pointing out flaws in your
> understanding is inherently rude, though I think you took it as such.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Well put Michael

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help with this code

2017-01-09 Thread Joel Goldstick
On Mon, Jan 9, 2017 at 1:02 PM, Gilmeh Serda
<gilmeh.ser...@nothing.here.invalid> wrote:
> On Mon, 09 Jan 2017 05:08:51 -0800, José Manuel Suárez Sierra wrote:
>
>> elements. For example, if we have a list_a=["a","b","c","d"] and
>> list_b=["a","b"] I want to obtain a new list_c containing elements that
>> match between these lists (a and b here),
>
> Perhaps this might work:
>
>>>> list(set(list_a).intersection(set(list_b)))
> ['a', 'b']
>
> HTH
> --
> Gilmeh
> --
> https://mail.python.org/mailman/listinfo/python-list

I was confused whether the OP wanted to retain the list order.  The
spec seemed unclear. If not, this is a nice approach.  Of course this
also removes duplicate values.

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: learning and experimenting python.

2016-12-31 Thread Joel Goldstick
On Sat, Dec 31, 2016 at 12:08 PM,  <einstein1...@gmail.com> wrote:
> We are not discussing here about English,
> But for python. Don't divert. Other wise someone thinks that I am doing this 
> for getting more posts.
> --
> https://mail.python.org/mailman/listinfo/python-list

If you stay around a while, einstein, you will see that the group will
wander off into (sometimes) interesting asides when the original
question seems to have been played out.  Its a form a creative
ignoring.

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: learning and experimenting python.

2016-12-31 Thread Joel Goldstick
On Sat, Dec 31, 2016 at 10:27 AM, Dennis Lee Bieber
<wlfr...@ix.netcom.com> wrote:
> On Sat, 31 Dec 2016 12:04:57 +, mm0fmf <n...@invalid.com> declaimed the
> following:
>
>>Though they do write road info upside down on the road surface,
>>typically XING with PED underneath. I had to ask what XINGPED meant till
>>my colleague driving said it was PEDXING, pedestrian crossing. Why write
>>it the wrong way though?
>
> For those I've encountered with multiple lines of text, the lines are
> placed in the order one sees them.
>
> Yes, in a helicopter they would be reversed, but from the view in a
> car, one sees the "PED" first, with the "XING" becoming visible as the
> "PED" begins to be blocked by the hood (or should I say "bonnet").

In the United States, ambulances often have their signage written
backwards so that it appears normal in a rear view mirror.  Do they do
that in other countries?


> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List comprehension

2016-12-30 Thread Joel Goldstick
On Fri, Dec 30, 2016 at 2:58 PM, Joaquin Alzola
<joaquin.alz...@lebara.com> wrote:
>
>
>>Now, this puzzles me:
>
>>>>> [x,y for a in data]
>>  File "", line 1
>>[x,y for a in data]
>  >  ^
>>SyntaxError: invalid syntax
>
>>I expected:
>>[(1, 2), (3, 4)]
>
> You can try [(x,z) for x,z in data].
> In your situation a takes the values (1,2) or (3,4) in the one that I put x 
> and z take the tupple values (x first one z second one).
>
>>>> [(x,z) for x,z in data]
> [(1, 2), (3, 4)]

I like yours better than mine.


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List comprehension

2016-12-30 Thread Joel Goldstick
On Fri, Dec 30, 2016 at 2:37 PM, Jason Friedman <jsf80...@gmail.com> wrote:
> $ python
> Python 3.6.0 (default, Dec 26 2016, 18:23:08)
> [GCC 4.8.4] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> data = (
> ... (1,2),
> ... (3,4),
> ... )
>>>> [a for a in data]
> [(1, 2), (3, 4)]
>
> Now, this puzzles me:
>
>>>> [x,y for a in data]
>   File "", line 1
> [x,y for a in data]
>^
> SyntaxError: invalid syntax
>
> I expected:
> [(1, 2), (3, 4)]
> --
> https://mail.python.org/mailman/listinfo/python-list

Thy this:

>>> [(a[0], a[1]) for a in data]
[(1, 2), (3, 4)]


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unicode script

2016-12-15 Thread Joel Goldstick
I think this might be what you want:
https://docs.python.org/3/howto/unicode.html#unicode-properties

On Thu, Dec 15, 2016 at 11:53 AM, Steve D'Aprano
<steve+pyt...@pearwood.info> wrote:
> Suppose I have a Unicode character, and I want to determine the script or
> scripts it belongs to.
>
> For example:
>
> U+0033 DIGIT THREE "3" belongs to the script "COMMON";
> U+0061 LATIN SMALL LETTER A "a" belongs to the script "LATIN";
> U+03BE GREEK SMALL LETTER XI "ξ" belongs to the script "GREEK".
>
>
> Is this information available from Python?
>
>
> More about Unicode scripts:
>
> http://www.unicode.org/reports/tr24/
> http://www.unicode.org/Public/UCD/latest/ucd/Scripts.txt
> http://www.unicode.org/Public/UCD/latest/ucd/ScriptExtensions.txt
>
>
> --
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: NameError

2016-11-23 Thread Joel Goldstick
On Wed, Nov 23, 2016 at 9:44 PM, Cai Gengyang <gengyang...@gmail.com> wrote:
>>>> pygame.draw.rect(screen, BROWN, [60, 400, 30, 45])
> Traceback (most recent call last):
> File "<pyshell#3>", line 1, in 
> pygame.draw.rect(screen, BROWN, [60, 400, 30, 45])
> NameError: name 'pygame' is not defined
>
> How to solve this error ?
> --
> https://mail.python.org/mailman/listinfo/python-list

have you imported pygame?

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python does not start

2016-11-17 Thread Joel Goldstick
On Thu, Nov 17, 2016 at 2:59 PM, Jelena Tavcar <jelena.tav...@gmail.com> wrote:
> How do I find stdlib files?
> Regards
> --
> https://mail.python.org/mailman/listinfo/python-list

First of all, your subject line doesn't seem related to your body
text.  Second of all, stdlib is a C thing as I recall, not python.
Can you be a bit more forthcoming about your issue?

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python -Simplebool

2016-10-05 Thread Joel Goldstick
es),','.join(result_list)))
> output.close()
>
> def GenerateCombinations(INPUT):
> StrBool={'True':True,'False':False}
> NodeState=[]
> Combine=[]
> for node_list in INPUT['mutation_list']:
> for node in open(node_list):
> NodeState.append((node.strip(),StrBool[INPUT['keep_state'][INPUT['mutation_list'].index(node_list)]]))
> if INPUT['mutation_mode']=='single':
> for mute_state in NodeState:
> Combine.append((mute_state,))
> return Combine
> elif INPUT['mutation_mode']=='double':
> for i in range(len(NodeState)):
> for j in range(i+1,len(NodeState)):
> if NodeState[i][0] != NodeState[j][0]:
> Combine.append((NodeState[i],NodeState[j]))
> print 'Total %s combinations.'%(len(Combine))
> return Combine
> if __name__ == '__main__':
> try:
> para=ParaParser(sys.argv[1])
> except:
> para=ParaParser('mutation.in')
> simu_mutation(para)
>
>
> After running this file, I got the following 
> error:/home/JPJ/Priya_Ph.D/simple_bool/simplebool/SimpleBool-master/BoolMutation.py
>  in ()
> 383 para=ParaParser(sys.argv[1])
> 384 except:
> --> 385 para=ParaParser('mutation.in')
> 386 simu_mutation(para)
>
> /home/JPJ/Priya_Ph.D/simple_bool/simplebool/SimpleBool-master/BoolMutation.py 
> in ParaParser(ParaFile)
> 254 }  # define parameters
> 255
> --> 256 for each_line in open(ParaFile).readlines():
> 257 para_name = each_line.split('=')[0].strip()
> 258 para_value = each_line.split('=')[1].strip()
>
> IOError: [Errno 2] No such file or directory: 'mutation.in'
>
>
> I can't understand, the problem here. Should I specify anything in the 
> Boolmutation.py file. Any help would be appreciated
> Thank you
> Regards
> Priya
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is duck-typing misnamed?

2016-08-27 Thread Joel Goldstick
On Sat, Aug 27, 2016 at 6:34 PM, Terry Reedy <tjre...@udel.edu> wrote:
> On 8/26/2016 7:58 PM, ROGER GRAYDON CHRISTMAN wrote:
>>
>> "If it walks like a duck, quacks like a duck,... "
>>
>> so there is indeed precedence for this so-called 'duck typing'
>>
>>
>> but wouldn't it be more Pythonic to call this 'witch typing'?
>>
>> "How do you know she is a witch?"
>>
>> "She looks like one."
>
>
> Given that people were once burned to death for 'looking like a witch' (or
> sounding or acting), and can still suffer socially for such reasons, this it
> not funny to me.  We should stick with ducks.
>
> --
> Terry Jan Reedy
>
> --
> https://mail.python.org/mailman/listinfo/python-list

which ducks?


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Print Error

2016-07-28 Thread Joel Goldstick
On Thu, Jul 28, 2016 at 1:40 PM, Cai Gengyang <gengyang...@gmail.com> wrote:
> How to debug this ?
>
>>>> print "This line will be printed."
> SyntaxError: Missing parentheses in call to 'print'
> --
> https://mail.python.org/mailman/listinfo/python-list

You are using python 3.x.  print is a function.  Use print("this line
will be printed")

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why not allow empty code blocks?

2016-07-24 Thread Joel Goldstick
On Sun, Jul 24, 2016 at 8:17 AM, Steven D'Aprano <st...@pearwood.info> wrote:
> On Sun, 24 Jul 2016 08:35 pm, BartC wrote:
>
>> I didn't want to get into this subject again, but Python's indentation
>> scheme is fragile.
>
> *shrug*
>
> Okay, it's fragile. In 20 (give or take a couple) years of programming in
> Python, do you know how many times this fragility has been an *actual*
> problem? Why don't you take a guess?
>
>
>> Given an otherwise correctly typed program that compiles with no errors,
>> then it is very easy (if Backspace or Delete is inadvertently pressed
>> for example), for an indent to disappear without your noticing,
>
> Not really. It depends on the editor, but typically you need to have your
> text insertion point somewhere in the indent.
>
> And when you do accidentally press Delete, what happens? The high-level
> structure of the code changes. Typically things will no longer align:
>
> def f():
> for x in seq:
> do_this()
> do_that()
> do_more()
>
> which is a SyntaxError. It requires quite the coincidence before you can
> accidentally delete an indent and have the code still run. Far more likely
> is that accidentally pressing delete will break the code in a way that
> can't be detected until runtime:
>
> def f():
> for x in seq:
> do_this()
> d_that()
> do_more()
>
> Conclusion: if you're the sort of person who habitually presses the Delete
> or Backspace key without paying attention, you're going to have a bad time.
>
> (Do other professions make arguments like this? Do carpenters, say, argue
> against nail guns because "well if you accidentally hold a loaded nail gun
> to your head, then press the trigger, bad things will happen"? Or is it
> just programmers who make a common practice of arguing that the programming
> language should protect the user from sheer carelessness?)
>
>
>> but a
>> program still compiles. And still runs without execution errors. But
>> might now be subtly wrong.
>
> That's certainly *theoretically* possible, but its really not likely. The
> only way it could happen is:
>
> - you have a block with at least two lines;
> - your insertion point is in the indent of the last line of the block;
> - but not the actual text part;
> - your editor is configured to dedent on Delete/Backspace, not just
>   delete a single space; or you're using tabs to indent;
> - and the block isn't followed by another block (e.g. if...else...)
>
>
>
>> Deleting any other character than a leading space or tab I think is more
>> likely to result in an error that would be noticed, generate a compile
>> error, or execute error ('variable not initialised'), or that goes wrong
>> more obviously.
>
> pi = 314159  # oops accidentally hit delete
>
>
> [...]
>> But my suggestion is simply that you can write:
>>
>>   for x in sequence:
>>   end
>>
>> instead of:
>>
>>   for x in sequence:
>>   pass
>>
>> The first now allows statements to be added or removed from the body of
>> the loop without needing to change the 'end'; it wouldn't look out of
>> place as a trailing 'pass' would.
>
> You know, I suspect that you've probably spent more time talking about the
> effort required to delete and insert "pass" than the *actual* effort spent
> by a hundred programmers deleting and inserting "pass" in their code.
>
>
>> But thinking about it some more, it wouldn't work. All the blocks that
>> don't now use 'end' would look odd. I think it would either have to be
>> all or nothing. I guess nothing.
>
>
>
>
> --
> Steven
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.
>
This thread is beginning to feel like a dog whistle for people who
like braces.  I've been python coding since 2009 I think, and I think
I have used pass less than a handful of times. ... and except for sets
and dicts, I can't remember using a {

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Appending an asterisk to the end of each line

2016-07-05 Thread Joel Goldstick
On Tue, Jul 5, 2016 at 7:03 PM, MRAB <pyt...@mrabarnett.plus.com> wrote:
> On 2016-07-05 23:05, Seymore4Head wrote:
>>
>> import os
>>
>> f_in = open('win.txt', 'r')
>> f_out = open('win_new.txt', 'w')
>>
>> for line in f_in.read().splitlines():
>> f_out.write(line + " *\n")
>>
>> f_in.close()
>> f_out.close()
>>
>> os.rename('win.txt', 'win_old.txt')
>> os.rename('win_new.txt', 'win.txt')
>>
>>
>> I just tried to reuse this program that was posted several months ago.
>> I am using a text flie that is about 200 lines long and have named it
>> win.txt.  The file it creates when I run the program is win_new.txt
>> but it's empty.
>>
> Although it creates a file called "win_new.txt", it then renames it to
> "win.txt", so "win_new.txt" shouldn't exist.
>
> Of course, if there's already a file called "win_old.txt", then the first
> rename will raise an exception, and you'll have "win_new.txt" and the
> original "win.txt".
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Why don't you comment out the renames, and see what happens?


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Appending an asterisk to the end of each line

2016-07-05 Thread Joel Goldstick
On Tue, Jul 5, 2016 at 6:29 PM, Seymore4Head
<Seymore4Head@hotmail.invalid> wrote:
> On Tue, 5 Jul 2016 18:27:25 -0400, Joel Goldstick
> <joel.goldst...@gmail.com> wrote:
>
>>On Tue, Jul 5, 2016 at 6:05 PM, Seymore4Head
>><Seymore4Head@hotmail.invalid> wrote:
>>> import os
>>>
>>> f_in = open('win.txt', 'r')
>>> f_out = open('win_new.txt', 'w')
>>>
>>> for line in f_in.read().splitlines():
>>> f_out.write(line + " *\n")
>>>
>>> f_in.close()
>>> f_out.close()
>>>
>>> os.rename('win.txt', 'win_old.txt')
>>> os.rename('win_new.txt', 'win.txt')
>>>
>>>
>>> I just tried to reuse this program that was posted several months ago.
>>> I am using a text flie that is about 200 lines long and have named it
>>> win.txt.  The file it creates when I run the program is win_new.txt
>>> but it's empty.
>>>
>>>
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>>
>>Are you running program in same folder as text file?
>
> Yes.  I just reinstalled Python.  Python is not installed in the same
> folder and I don't remember if it needs to have path entered.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list

So, if you type python, do you enter the python shell?

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   6   7   8   >