Re: Get Count of function arguments passed in

2019-09-11 Thread Sayth Renshaw
On Wednesday, 11 September 2019 20:25:32 UTC+10, Sayth Renshaw wrote: > On Wednesday, 11 September 2019 20:11:21 UTC+10, Sayth Renshaw wrote: > > Hi > > > > I want to allow as many lists as needed to be passed into a function. > > But how can I determine how man

Re: Get Count of function arguments passed in

2019-09-11 Thread Sayth Renshaw
On Wednesday, 11 September 2019 20:11:21 UTC+10, Sayth Renshaw wrote: > Hi > > I want to allow as many lists as needed to be passed into a function. > But how can I determine how many lists have been passed in? > > I expected this to return 3 but it only returned 1. > >

Get Count of function arguments passed in

2019-09-11 Thread Sayth Renshaw
, matrix2)) def add(*matrix): print(len(locals())) add(matrix1,matrix2,matrix3) Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: pandas loc on str lower for column comparison

2019-09-09 Thread Sayth Renshaw
On Tuesday, 10 September 2019 12:56:36 UTC+10, Sayth Renshaw wrote: > On Friday, 6 September 2019 07:52:56 UTC+10, Piet van Oostrum wrote: > > Piet van Oostrum <> writes: > > > > > That would select ROWS 0,1,5,6,7, not columns. > > > To select columns

Re: pandas loc on str lower for column comparison

2019-09-09 Thread Sayth Renshaw
-versus-copy So tried this df['c'] = df.apply(lambda df1: df1['Current Team'].str.lower().str.strip() == df1['New Team'].str.lower().str.strip(), axis=1) Based on this SO answer https://stackoverflow.com/a/46570641 Thoughts? Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: pandas loc on str lower for column comparison

2019-09-05 Thread Sayth Renshaw
That is actually consistent with Excel row, column. Can see why it works that way then. Thanks -- https://mail.python.org/mailman/listinfo/python-list

Re: pandas loc on str lower for column comparison

2019-09-04 Thread Sayth Renshaw
On Sunday, 1 September 2019 10:48:54 UTC+10, Sayth Renshaw wrote: > I've created a share doc same structure anon data from my google drive. > > https://drive.google.com/file/d/0B28JfFTPNr_lckxQRnFTRF9UTEFYRUVqRWxCNVd1VEZhcVNr/view?usp=sharing > > Sayth I tried creating

Re: Need help: integrating unittest with setuptools

2019-09-01 Thread Sayth Renshaw
can > think of with Google but can't find why or how. Could you help me? Thanks. > > -- > YX. D. Does this help? https://stackoverflow.com/questions/4320761/importerror-no-module-named-winreg-python3 Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: How to create a list and append to list inside a mqtt and GUI program?

2019-09-01 Thread Sayth Renshaw
print("Publishing message to topic", > "microscope/light_sheet_microscope/UI") > client.publish("microscope/light_sheet_microscope/UI", > device_message) > time.sleep(2) # wait > client.loop_stop() # stop the loop > > def closeEvent(self, event): > self.close() > > test2.py > > from PyQt5 import QtCore, QtGui, QtWidgets > import sys > from PyQt5.QtWidgets import * > from PyQt5.QtCore import * > from PyQt5 import QtWidgets, uic > > class SubWindow(QWidget): > def __init__(self, parent = None): > super(SubWindow, self).__init__(parent) > self.setMinimumSize(QSize(300, 250)) > label = QLabel("Sub Window", self) > > self.modeButton = QtWidgets.QPushButton("Click me",self) > self.modeButton.setGeometry(QtCore.QRect(10, 40, 81, 23)) > > self.modeButton.clicked.connect(self.modFun) > > > > def modFun(self): > print("Hello there i'm Click me") > > def closeEvent(self, event): > self.close() > > Thanks. list_of_file_name = [] my_file = getGUIFilename() list.append(my_file) Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: pandas loc on str lower for column comparison

2019-09-01 Thread Sayth Renshaw
I've created a share doc same structure anon data from my google drive. https://drive.google.com/file/d/0B28JfFTPNr_lckxQRnFTRF9UTEFYRUVqRWxCNVd1VEZhcVNr/view?usp=sharing Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: pandas loc on str lower for column comparison

2019-08-31 Thread Sayth Renshaw
On Sunday, 1 September 2019 05:19:34 UTC+10, Piet van Oostrum wrote: > Sayth Renshaw writes: > > > But on both occasions I receive this error. > > > > # KeyError: 'the label [Current Team] is not in the [index]' > > > > if I test df1 before tryi

Re: pandas loc on str lower for column comparison

2019-08-29 Thread Sayth Renshaw
.strip() and df1 = df[['UID','Name','New Leader','Current Team', 'New Team']].copy() df1['Difference'] = df1.loc['Current Team'].str.lower().str.strip() == df1.loc['New Team'].str.lower().str.strip() But on both occasions I receive this error. # KeyError: 'the label [Current Team] is not in the [index]' if I test df1 before trying to create the new column it works just fine. Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: [SOLVED] Re: Compare zip lists where order is important

2019-08-29 Thread Sayth Renshaw
On Thursday, 29 August 2019 20:33:46 UTC+10, Peter Otten wrote: > Sayth Renshaw wrote: > > > will find the added > > pairs, but ignore the removed ones. Is that what you want? > > > > Yes, I think. I want to find the changed pairs. The people that moved team > &

Re: pandas loc on str lower for column comparison

2019-08-29 Thread Sayth Renshaw
'New Team')] > > Or maybe even make an explicit copy: > > df1 = df[['UID','Name','New Leader','Current Team', 'New Team']].copy() Thank you so much. Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: [SOLVED] Re: Compare zip lists where order is important

2019-08-29 Thread Sayth Renshaw
will find the added pairs, but ignore the removed ones. Is that what you want? Yes, I think. I want to find the changed pairs. The people that moved team numbers. Sayth -- https://mail.python.org/mailman/listinfo/python-list

pandas loc on str lower for column comparison

2019-08-28 Thread Sayth Renshaw
Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy If I update the line to use loc as this I still receive a long error. df1['Difference'] = df1.loc['Curren

[SOLVED] Re: Compare zip lists where order is important

2019-08-28 Thread Sayth Renshaw
On Thursday, 29 August 2019 14:03:44 UTC+10, Sayth Renshaw wrote: > On Thursday, 29 August 2019 13:53:43 UTC+10, Sayth Renshaw wrote: > > On Thursday, 29 August 2019 13:25:01 UTC+10, Sayth Renshaw wrote: > > > Hi > > > > > > Trying to find whats changed in

Re: Compare zip lists where order is important

2019-08-28 Thread Sayth Renshaw
On Thursday, 29 August 2019 13:53:43 UTC+10, Sayth Renshaw wrote: > On Thursday, 29 August 2019 13:25:01 UTC+10, Sayth Renshaw wrote: > > Hi > > > > Trying to find whats changed in this example. Based around work and team > > reschuffles. > > > > So fi

Re: Compare zip lists where order is important

2019-08-28 Thread Sayth Renshaw
On Thursday, 29 August 2019 13:25:01 UTC+10, Sayth Renshaw wrote: > Hi > > Trying to find whats changed in this example. Based around work and team > reschuffles. > > So first I created my current teams and then my shuffled teams. > > people = ["Tim","

Re: How to use regex to search string between {}?

2019-08-28 Thread Sayth Renshaw
> > A site like http://www.pyregex.com/ allows you to check your regex with > slightly fewer clicks and keystrokes than editing your program. Thanks Jason -- https://mail.python.org/mailman/listinfo/python-list

Compare zip lists where order is important

2019-08-28 Thread Sayth Renshaw
attempting to compare for change. [i for i, j in zip(teams, shuffle_teams) if i != j] #Result [('Tim', 1), ('Ally', 2), ('Fred', 3), ('Fredricka', 3)] #Expecting to see [('Fredricka', 1),('Tim', 2)] What's a working way to go about this? Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Enumerate - int object not subscriptable

2019-08-20 Thread Sayth Renshaw
On Wednesday, 21 August 2019 03:16:01 UTC+10, Ian wrote: > Or use the "pairwise" recipe from the itertools docs: > > from itertools import tee > > def pairwise(iterable): > "s -> (s0,s1), (s1,s2), (s2, s3), ..." > a, b = tee(iterable) > next(b, None) > return zip(a, b) > > for n

Enumerate - int object not subscriptable

2019-08-20 Thread Sayth Renshaw
, 1. But am receiving TypeError: 'int' object is not subscriptable Why? Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Copying a row from a range of Excel files to another

2019-06-26 Thread Sayth Renshaw
this? > > > > -- > Cecil Westerhof Pandas may work out better. import pandas as pd df = pd.read_excel('spreadsheet') # find the row by filtering with regex df2 = df.'column'.str.contains('criteria as regex') df2.pd.save_excel('output.xlsx') Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: for line3 in myips matching too longer matches.

2019-06-26 Thread Sayth Renshaw
match 10.10.168.2[0-9] > > If someone out there knows a simple solution. I would love to see it. > Thanks in advance. > crzzy1 Not sure exactly what the input is but a comprehension would do this. [x for x in input_line.split(' ') if == '10.10.168.2'] Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: pandas split and melt()

2019-06-26 Thread Sayth Renshaw
9-06-22 10:00:00 Doe, John;#42;Robbins, Rita; > > [2 rows x 2 columns] > Session date Consultant > 0 2019-06-21 11:15:00 WNEWSKI, Joan > 1 2019-06-21 11:15:00BALIN, Jock > 2 2019-06-21 11:15:00DUNE, Colem > 3 2019-06-22 10:00:00 Doe, John > 4 2019-06-22 10:00:00 Robbins, Rita > > [5 rows x 2 columns] > $ Mind a little blown :-). Going to have to play and break this several times to fully get it. Thanks Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: pandas split and melt()

2019-06-26 Thread Sayth Renshaw
t']].str.contains(r'/\b[^\d\W]+\b/g') neither option works as the column is a list. Thanks Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: pandas split and melt()

2019-06-25 Thread Sayth Renshaw
['Consultant'] = completed_tasks['Consultant'].str.contains(pattern) ... Works without the regex which causes this error AttributeError: Can only use .str accessor with string values, which use np.object_ dtype pattern = "\\#d" completed_tasks['Consultant'] = completed_tasks['Consultant'].str.split(pat = ";") Sayth -- https://mail.python.org/mailman/listinfo/python-list

pandas split and melt()

2019-06-25 Thread Sayth Renshaw
consultants name? NB. There are varied amounts of consultants so splitting across columns is uneven. if it was even melt seems like it would be good https://dfrieds.com/data-analysis/melt-unpivot-python-pandas Thanks Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: generator to write N lines to file

2019-06-24 Thread Sayth Renshaw
ager: > > from itertools import islice > from contextlib import contextmanager > > infile = ... > outfile = ... > > @contextmanager > def head(infile, numlines): > with open(infile) as f: > yield islice(f, numlines) > > with open(outfile, "w

generator to write N lines to file

2019-06-23 Thread Sayth Renshaw
with open(infile, 'r+') as f: lines_gen = islice(f, lineNum) yield lines_gen for line in getWord(fileName, 5): with open(dumpName, 'a') as f: f.write(line) Thanks, Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Function to determine list max without itertools

2019-04-19 Thread Sayth Renshaw
it could be very important so then async await might be an option. Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Function to determine list max without itertools

2019-04-19 Thread Sayth Renshaw
On Friday, 19 April 2019 17:01:33 UTC+10, Sayth Renshaw wrote: > Set the first item in the list as the current largest. > Compare each subsequent integer to the first. > if this element is larger, set integer. def maxitwo(listarg): myMax = listarg[0] fo

Re: Function to determine list max without itertools

2019-04-19 Thread Sayth Renshaw
Set the first item in the list as the current largest. Compare each subsequent integer to the first. if this element is larger, set integer. -- https://mail.python.org/mailman/listinfo/python-list

Re: Function to determine list max without itertools

2019-04-18 Thread Sayth Renshaw
es the first item and comparison continues. Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Function to determine list max without itertools

2019-04-18 Thread Sayth Renshaw
> > > It's still overly complicated. > This is where I have ended up. Without itertools and max its what I got currently. def maximum(listarg): myMax = listarg[0] for item in listarg: for i in listarg[listarg.index(item)+1:len(listarg)]: if myMax < i:

Re: Function to determine list max without itertools

2019-04-18 Thread Sayth Renshaw
(items)]: if myMax < i: myMax = i else: pass return myMax if __name__ == "__main__": print(maximum([4,3,6,2,1,4])) Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Function to determine list max without itertools

2019-04-17 Thread Sayth Renshaw
= [] if seq: max_val = seq[0] for i,val in ((i,val) for i,val in enumerate(seq) if val >= max_val): if val == max_val: max_indices.append(i) else: max_val = val max_indices = [i] return max_indices This is probably the nicest one but still uses Max. >>> a=[5,4,3,2,1] >>> def eleMax(items, start=0, end=None): ... return max(items[start:end]) Thanks Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Importing module from another subdirectory

2019-04-17 Thread Sayth Renshaw
fficult to be honest. https://chrisyeh96.github.io/2017/08/08/definitive-guide-python-imports.html#example-directory-structure Then there was this rather long list of traps. http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html Most guides say it was fixed in 3.3 but still seems quite confusing post 3.3 Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Function to determine list max without itertools

2019-04-17 Thread Sayth Renshaw
should work but doesn't. Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: hello this ali .. i want some question about python

2019-04-05 Thread Sayth Renshaw
On Saturday, 6 April 2019 08:21:51 UTC+11, maak khan wrote: > i need your help guys .. plz With? -- https://mail.python.org/mailman/listinfo/python-list

Re: I really liked this Javscript FizzBuzz can it be as nice in Python?

2019-04-05 Thread Sayth Renshaw
, n-1), (s,))) > > fizzbuzz = map("".join, zip(make("Fizz", 3), make("Buzz", 5))) > > for i, fb in enumerate(islice(fizzbuzz, 100), 1): > print(fb or i) Thanks Sayth -- https://mail.python.org/mailman/listinfo/python-list

I really liked this Javscript FizzBuzz can it be as nice in Python?

2019-04-04 Thread Sayth Renshaw
: output += "Fizz" if (num % 5 == 0): output += "Buzz" print(output or num) Haven't quite got it. But is possible nice and succinct like the javascript version. Maybe lambda will do it, gonna try that. Any unique mindlowing style FizzBuzz I would never have

Re: scalable bottleneck

2019-04-03 Thread Sayth Renshaw
On Thursday, 4 April 2019 10:51:35 UTC+11, Paul Rubin wrote: > Sayth Renshaw writes: > > for x in range ( max_root ): > > 1) Do you see a memory bottleneck here? If so, what is it? > > 2) Can you think of a way to fix the memory bottleneck? > > In Python 2, range(

scalable bottleneck

2019-04-03 Thread Sayth Renshaw
. But is this the correct way to go? More of a am I thinking correctly questino. item = 0 while item < MAX: print(supply_squares(item)) item += 1 Thanks Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Implement C's Switch in Python 3

2019-02-02 Thread Sayth Renshaw
ame across a problem. "11st", "12nd", "13rd"? > > [snip] > > > > Output: > > > >>>> for day in range(1, 32): > > print( nthSuffix(day)) > > > > 1st > > 2nd > > 3rd > > 4th > > 5

Re: Implement C's Switch in Python 3

2019-02-02 Thread Sayth Renshaw
uffix in mapping.items(): > if x in key: > return suffix > return "th" > > However, for big dictionaries (with many keys) you loose a key strength > of dicts: constant time lookup. You can see the above code (and the > earlier "if" code) are rather linear, with run time going up linearly > with the number of keys. You're better with the int->string single value > dict version. > > Cheers, > Cameron Simpson It seems odd with C having switch that its cleaner and more efficient than python where we are having to implement our own functions to recreate switch everytime. Or perhaps use a 3rd party library like https://github.com/mikeckennedy/python-switch You have both given good options, it seems there are no standard approaches in this case. Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Implement C's Switch in Python 3

2019-02-02 Thread Sayth Renshaw
t a function that uses a dictionary. Not sure how to supply list into it to keep it brief and with default case of 'th'. This is my current code. def f(x): return { [1, 21, 31]: "st", [2, 22]: "nd", [3, 23]: "rd", }.get(x, &quo

Re: Use a function arg in soup

2018-08-01 Thread Sayth Renshaw
Sayth -- https://mail.python.org/mailman/listinfo/python-list

Use a function arg in soup

2018-08-01 Thread Sayth Renshaw
deas on how the function argument can be used as the search attribute? Thanks Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Format list of list sub elements keeping structure.

2018-07-24 Thread Sayth Renshaw
solve each small part, and > (3) assemble the whole puzzle. This is a skill you must > master. And it's really not difficult. It just requires a > different way of thinking about tasks. Thank you Rick, good advice. I really am enjoying coding at the moment, got myself and life in a good headspace. Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Format list of list sub elements keeping structure.

2018-07-24 Thread Sayth Renshaw
ving to figure out the structure each time. Just want to automate that part so I can move through the munging part and spend more time on higher value tasks. Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Format list of list sub elements keeping structure.

2018-07-24 Thread Sayth Renshaw
on 3 import operator def getFromDict(dataDict, mapList): return reduce(operator.getitem, mapList, dataDict) def setInDict(dataDict, mapList, value): getFromDict(dataDict, mapList[:-1])[mapList[-1]] = value Then get the values from the keys >>> getFromDict(dataDict, ["a", "r"]) 1 That would mean I could using my function if I get it write be able to feed it any json, get all the full paths nicely printed and then feed it back to the SO formula and get the values. It would essentially self process itself and let me get a summary of all keys and their data. Thanks Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Format list of list sub elements keeping structure.

2018-07-23 Thread Sayth Renshaw
On Tuesday, 24 July 2018 14:25:48 UTC+10, Rick Johnson wrote: > Sayth Renshaw wrote: > > > elements = [['[{0}]'.format(element) for element in elements]for elements > > in data] > > I would suggest you avoid list comprehensions until you master long-form &g

Re: Format list of list sub elements keeping structure.

2018-07-23 Thread Sayth Renshaw
On Tuesday, 24 July 2018 14:25:48 UTC+10, Rick Johnson wrote: > Sayth Renshaw wrote: > > > elements = [['[{0}]'.format(element) for element in elements]for elements > > in data] > > I would suggest you avoid list comprehensions until you master long-form &g

Re: Format list of list sub elements keeping structure.

2018-07-23 Thread Sayth Renshaw
lossary]', '[GlossDiv]', '[GlossList]'], ['[glossary]', '[GlossDiv]', '[GlossList]', '[GlossEntry]'], .] I used. elements = [['[{0}]'.format(element) for element in elements]for elements in data] Is there a good way to s

Re: Format list of list sub elements keeping structure.

2018-07-23 Thread Sayth Renshaw
out) print(answer) Think I need to bring it in a list not an element of a list and process it. Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Format list of list sub elements keeping structure.

2018-07-23 Thread Sayth Renshaw
ssDiv', 'GlossList', 'GlossEntry', 'GlossDef', 'GlossSeeAlso', 0], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', 'GlossSeeAlso', 1], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossSee']] I am trying to change it to be. [['glossary'], ['glossary']['title'], ['glossary']['GlossDiv'], ] Currently when I am formatting I am flattening the structure(accidentally). for item in data: for elem in item: out = ("[{0}]").format(elem) print(out) Which gives [glossary] [title] [GlossDiv] [title] [GlossList] [GlossEntry] [ID] [SortAs] [GlossTerm] [Acronym] [Abbrev] [GlossDef] [para] [GlossSeeAlso] [0] [1] [GlossSee] Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Data Integrity Parsing json

2018-04-25 Thread Sayth Renshaw
On Thursday, 26 April 2018 07:57:28 UTC+10, Paul Rubin wrote: > Sayth Renshaw writes: > > What I am trying to figure out is how I give myself surety that the > > data I parse out is correct or will fail in an expected way. > > JSON is messier than people think. Here&#

Re: Looping on a list in json

2017-11-04 Thread Sayth Renshaw
sts = {} >for n, item in enumerate(result): ># if this one is interested / not -filtered: >print(n, item) >runner_lists[n] = result[n]["RacingFormGuide"]["Event"]["Runners"] Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Looping on a list in json

2017-11-04 Thread Sayth Renshaw
Sorry figured it. Needed to use n to iterate when creating. runner_lists = {} for n, item in enumerate(result): # if this one is interested / not -filtered: print(n, item) runner_lists[n] = result[n]["RacingFormGuide"]["Event"]["R

Re: Looping on a list in json

2017-11-04 Thread Sayth Renshaw
em in enumerate(result): # if this one is interested / not -filtered: print(n, item) runner_lists[n] = result["RacingFormGuide"]["Event"]["Runners"] ## Produces Traceback (most recent call last): dict_keys(['RaceDay', 'ErrorInfo', 'Success']) File "/home/sayth/PycharmProjects/ubet_api_mongo/parse_json.py", line 31, in runner_lists[n] = result["RacingFormGuide"]["Event"]["Runners"] TypeError: list indices must be integers or slices, not str Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Read Firefox sqlite files with Python

2017-11-04 Thread Sayth Renshaw
e noise. > > > > > -- > Steve > “Cheer up,” they said, “things could be worse.” So I cheered up, and sure > enough, things got worse. https://stackoverflow.com/a/18601429 Version mismatch between sqlite CLI and python sqlite API? I created again my db from the script ins

Re: Looping on a list in json

2017-11-04 Thread Sayth Renshaw
gt;import json > >from pprint import pprint > > > >with open(r'/home/sayth/Projects/results/Canterbury_2017-01-20.json', 'rb') > >as f, open('socks3.json','w') as outfile: > >to_read = json.load(f) > [...] > >me

Looping on a list in json

2017-11-04 Thread Sayth Renshaw
Hi I want to get a result from a largish json api. One section of the json structure returns lists of data. I am wanting to get each resulting list returned. This is my code. import json from pprint import pprint with open(r'/home/sayth/Projects/results/Canterbury_2017-01-20.json'

Re: pathlib PurePosixPath

2017-10-10 Thread Sayth Renshaw
IX paths don't apply to your file > system, and... > > > OSError: [Errno 22] Invalid argument: > > 'C:\\Users\\Sayth\\Projects\\results/Warwick Farm2017-09-06T00:00:00.json' > > ... the colon is invalid on Windows file systems. You'll have to > replace those

pathlib PurePosixPath

2017-10-10 Thread Sayth Renshaw
= r.json() if data["RaceDay"] is not None: file_name = data["RaceDay"]["Meetings"][0]["VenueName"] + data["RaceDay"]["MeetingDate"] + '.json' result_path = pathlib.PurePosixPath(r'C:\Users\Sa

Re: Suggestions on storing, caching, querying json

2017-10-06 Thread Sayth Renshaw
On Thursday, 5 October 2017 15:13:43 UTC+11, Sayth Renshaw wrote: > HI > > Looking for suggestions around json libraries. with Python. I am looking for > suggestions around a long term solution to store and query json documents > across many files. > > I will be

Suggestions on storing, caching, querying json

2017-10-04 Thread Sayth Renshaw
://objectpath.org/reference.html Looking to leverage your experience. Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: None is None but not working

2017-09-28 Thread Sayth Renshaw
Thank you it was data["RaceDay"] that was needed. ata = r.json() if data["RaceDay"] is None: print("Nothing here") else: print(data["RaceDay"]) Nothing here Nothing here Nothing here {'MeetingDate': '2017-01-11T00:0

None is None but not working

2017-09-27 Thread Sayth Renshaw
print(data["RaceDay"]) and I get output of None None {'MeetingDate': '2017-01- ... and so on. How can I actually get this to check? If i use type(data) I also get None. Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Easy way to get a list of tuples.

2017-09-21 Thread Sayth Renshaw
> > > > Thanks Thomas yes you are right with append. I have tried it but just > > can't get it yet as append takes only 1 argument and I wish to give it 3. > > > You have not showed us what you tried, but you are probably missing a pair > of brackets. > > C:\Users\User>python > Python 3.6.0 (v

Re: Easy way to get a list of tuples.

2017-09-21 Thread Sayth Renshaw
On Thursday, 21 September 2017 20:31:28 UTC+10, Thomas Jollans wrote: > On 2017-09-21 12:18, Sayth Renshaw wrote: > > This is my closest code > > > > data = r.json() > > > > raceData = [] > > > > for item in data["RaceDay"]['Meeting

Easy way to get a list of tuples.

2017-09-21 Thread Sayth Renshaw
this [('CLASS 3 HANDICAP', 1, 1000), ('BM 90 HANDICAP', 2, 1600), ('HERITAGE STAKES', 3, 1100), ('BILL RITCHIE HANDICAP', 4, 1400), ('TEA ROSE STAKES', 5, 1400), ('GEORGE MAIN STAKES', 6, 1600), ('THE SHORTS', 7, 1100), ('KINGTON TOWN STAKES', 8, 2000), ('BM 84 HANDICAP', 9, 1200)] I get close creating a list of elements but each attempt I try to create the list of tuples fails. This is my closest code data = r.json() raceData = [] for item in data["RaceDay"]['Meetings'][0]['Races']: raceDetails = item['RacingFormGuide']['Event']['Race'] raceData += (raceDetails['Name'],raceDetails['Number'],raceDetails['Distance']) print(raceDetails) which returns ['CLASS 3 HANDICAP', 1, 1000, 'BM 90 HANDICAP', 2, 1600, 'HERITAGE STAKES', 3, 1100, 'BILL RITCHIE HANDICAP', 4, 1400, 'TEA ROSE STAKES', 5, 1400, 'GEORGE MAIN STAKES', 6, 1600, 'THE SHORTS', 7, 1100, 'KINGTON TOWN STAKES', 8, 2000, 'BM 84 HANDICAP', 9, 1200] How do I get the tuples? Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Why is my class undefined?

2017-08-16 Thread Sayth Renshaw
itt") > > 15 print(frog.ftype) > > 16 print(frog.word) > > > > NameError: name 'frog' is not defined > > > > what exactly am I doing wrong? > > The if __name__ == "__main__" block is inside the class declaration > block, so at the point that it runs the class has not been created > yet. Try removing the indentation to place it after the class block > instead. Thank you that had me bugged I just couldn't see it. Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Why is my class undefined?

2017-08-16 Thread Sayth Renshaw
5 self.word = ftype in frog() 12 13 if __name__ == "__main__": ---> 14 tree_frog = frog("Tree Frog", "Ribbitt") 15 print(frog.ftype) 16 print(frog.word) NameError: name 'frog' is not defined what exactly am I doing wrong? Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Test 0 and false since false is 0

2017-07-08 Thread Sayth Renshaw
>>> after = sorted(before, key=lambda x: x == 0 and type(x) == int) it is really good, however I don't understand it enough to reimplement something like that myself yet. Though I can that lambda tests for 0 that is equal to an int why does sorted put them to the end? Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Test 0 and false since false is 0

2017-07-06 Thread Sayth Renshaw
On Friday, 7 July 2017 12:46:51 UTC+10, Rick Johnson wrote: > On Thursday, July 6, 2017 at 9:29:29 PM UTC-5, Sayth Renshaw wrote: > > I was trying to solve a problem and cannot determine how to filter 0's but > > not false. > > > > Given a list like this > &g

Test 0 and false since false is 0

2017-07-06 Thread Sayth Renshaw
, 1, 1, 3, [], 1, 9, {}, 9, 0, 0, 0, False, 0, 0, 0, 0, 0, 0, 0] I have tried or conditions of v == False etc but then the 0's being false also aren't moved. How can you check this at once? Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Generator - Provide parameters to url - requests

2017-07-05 Thread Sayth Renshaw
# note there are no implicit arguments like `base` in your code for _ in range(numdays): yield first first += ONE_DAY Thanks Sayth -- https://mail.python.org/mailman/listinfo/python-list

Generator - Provide parameters to url - requests

2017-07-04 Thread Sayth Renshaw
then: # open a file for writing using url paramters with open(SR + DAY + MONTH + YEAR + '.json', 'w') as f: # Do stuff from here not relevant to question. I have just gotten lost. Is there an easier way to go about this? Cheers Sayth -- https://mail.python.or

Re: Create a list of dates for same day of week in a year

2017-06-28 Thread Sayth Renshaw
25, 23, 58, 11), > datetime.datetime(2017, 12, 27, 23, 58, 11)]) > > In [45]: Thanks. I am just researching now the format that has come out. unclear what 58 represents. Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Create a list of dates for same day of week in a year

2017-06-27 Thread Sayth Renshaw
https://docs.python.org/2/library/calendar.html#calendar.Calendar.itermonthdays In [20]: calendar.setfirstweekday(calendar.SATURDAY) In [21]: calendar.firstweekday() Out[21]: 5 Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Create a list of dates for same day of week in a year

2017-06-27 Thread Sayth Renshaw
ry it? Also checked out Python Arrow http://arrow.readthedocs.io/en/latest/ as it expands on the python standard library but I couldn't find an obvious example of this. Thoughts or examples? Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Better way to do this dict comprehesion

2017-03-08 Thread Sayth Renshaw
gt;> find_it(test_seq) But what may be the smallest thing in this i had no idea I could do [result] = blah and get a generator on the return variable that seems insane. Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Better way to do this dict comprehesion

2017-03-07 Thread Sayth Renshaw
ther adding to a set or removing from > it. At the end, your set should contain exactly one element. I'll let > you write the actual code :) > > ChrisA ChrisA the way it sounds through the list is like filter with map and a lambda. http://www.python-course.eu/lambda.php Hav

Better way to do this dict comprehesion

2017-03-07 Thread Sayth Renshaw
appearing an odd number of times given that is there a neater way to get the answer? Thanks Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: How to flatten only one sub list of list of lists

2017-03-01 Thread Sayth Renshaw
27;, 'Machinegun Jubs', '6', '53', '77', '6', '2', '1', '1 $71685.00'] > ['46295', 'Zara Bay', '1', '53', '77', '12', '2', '3', '3 $112645.00'] I went for the one I can understand which was inplace def flatten_inplace(rows, index): for row in rows: row[index:index + 1] = row[index] return rows See now if I can make it more adaptable to use it in some other situations, quite useful. Thanks Sayth -- https://mail.python.org/mailman/listinfo/python-list

How to flatten only one sub list of list of lists

2017-02-28 Thread Sayth Renshaw
#x27;, '53', '77', '6', '2', '1', '1 $71685.00'], ['46295', 'Zara Bay', '1', '53', '77', '12', '2', '3', '3 $112645.00']] Been looking around but most solutions just entirely flatten everything. This was popular on SO but yeah it flattens everything I want to be more selective def flatten(lst): for elem in lst: if type(elem) in (tuple, list): for i in flatten(elem): yield i else: yield elem What I am thinking is that if for each list the sublist should be at index 1, so [0][1] [1][1] [2][1] for item in list: item[1] - somehow flatten. Thoughts? Sayth -- https://mail.python.org/mailman/listinfo/python-list

Is there a good process or library for validating changes to XML format

2017-01-06 Thread Sayth Renshaw
lt for PyXB and generateDS (https://pythonhosted.org/generateDS/). Both seem to be libraries for generating bindings to structures for parsing so maybe I am searching the wrong thing. What is the right thing to search? Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Screwing Up looping in Generator

2017-01-06 Thread Sayth Renshaw
race_writer = csv.writer(csvf, delimiter=',' ) thanks for your time and assistance. It's much appreciated Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Screwing Up looping in Generator

2017-01-06 Thread Sayth Renshaw
x27;) as csvf: for file in rootobs: # create and write csv Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Screwing Up looping in Generator

2017-01-06 Thread Sayth Renshaw
") with open(write_to, 'w', newline='') as csvf: for file in rootobs: # create and write csv Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Screwing Up looping in Generator

2017-01-06 Thread Sayth Renshaw
On Wednesday, 4 January 2017 12:36:10 UTC+11, Sayth Renshaw wrote: > So can I call the generator twice and receive the same file twice in 2 for loops? > > Once to get the files name and the second to process? > > for file in rootobs: > base = os.path.

Re: Is there a good process or library for validating changes to XML format?

2017-01-05 Thread Sayth Renshaw
It definitely has more features than i knew http://xmlsoft.org/xmllint.html Essentially thigh it appears to be aimed at checking validity and compliance of xml. I why to check the structure of 1 xml file against the previous known structure to ensure there are no changes. Cheers Sayth

Is there a good process or library for validating changes to XML format?

2017-01-04 Thread Sayth Renshaw
lt for PyXB and generateDS (https://pythonhosted.org/generateDS/). Both seem to be libraries for generating bindings to structures for parsing so maybe I am searching the wrong thing. What is the right thing to search? Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Screwing Up looping in Generator

2017-01-04 Thread Sayth Renshaw
race_writer = csv.writer(csvf, delimiter=',' ) thanks for your time and assistance. It's much appreciated Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Screwing Up looping in Generator

2017-01-03 Thread Sayth Renshaw
newline='') as csvf: for file in rootobs: # create and write csv Sayth -- https://mail.python.org/mailman/listinfo/python-list

Re: Screwing Up looping in Generator

2017-01-03 Thread Sayth Renshaw
On Wednesday, 4 January 2017 12:36:10 UTC+11, Sayth Renshaw wrote: > So can I call the generator twice and receive the same file twice in 2 for > loops? > > Once to get the files name and the second to process? > > for file in rootobs: > base = os.pa

Re: Screwing Up looping in Generator

2017-01-03 Thread Sayth Renshaw
quot;) with open(write_to, 'w', newline='') as csvf: for file in rootobs: # create and write csv Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list

  1   2   3   >