First ever code review post, so I hope I’m doing it right. My understanding of this site is that it is a place to post stuff like this for feedback and criticism. If that isn’t the case, I apologise for my misunderstanding.
I’m teaching myself Python 3 and I’m pretty near the start. I couldn’t find a simple description of a file parser, so I spent a frankly embarrassing amount of time trying to craft one, and this is the result:
def parse(file, startTag, endTag): bears= bearFile = open(file, 'r') for bearLine in bearFile: if startTag in bearLine: bear = bearFile.readline() while not (endTag in bear): bears.append(bear.strip()) bear = bearFile.readline() return bears
I tested it using:
print(parse("bears.txt", "==start==", "==end=="))
…on a file which looked like this:
This file contains a list of bears. Bears are below, between the start and end tags. ==start== Grizzly Polar Koala Panda Spectacled Sun ==end== These are some more tags, listing some false bears: ==start== Purple Hairless Aquatic Flying ==end==
…and it works! The output is:
['Grizzly', 'Polar', 'Koala', 'Panda', 'Spectacled', 'Sun', 'Purple', 'Hairless', 'Aquatic', 'Flying']
With some obvious flaws, including:
1 – I can’t work out how to ignore empty lines between the tags without using another if. I wondered if it might be better to do this later, and strip out all the ” entries, perhaps as an argument option.
2 – It depends on new lines because of the
readline method, so using something else like a comma as a delimiter is currently beyond me.
3 – If there is no end tag, it loops forever.
except are quite new to me right now.
I hope I’m not just wasting everyone’s time by being here…
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!