Software Development and Programming Careers (Official Discussion Thread)

.r.

Veteran
Joined
Jul 2, 2015
Messages
14,122
Reputation
4,870
Daps
65,184
Quick question

I'm messing with python 2.7, and attempted to run a program to scape a site.
@ line 46 (code below) It stated I needed to create an array, which I think is correct.
Yet I keep getting the following error.

Code:
Traceback (most recent call last):
  File "./bloom1.py", line 51, in <module>
    for pg in quote_page:  
NameError: name 'quote_page' is not defined

And suggestions?

Code:
# !/usr/local/bin/python
# python 2
#
# Source code
#
# craw a website (http://www.bloomberg.com/quote/SPX:IND.com), list all url under a specific given path
# To use type in "python" and name of file, then run.

#import libraries
from bs4 import BeautifulSoup
import requests
import urllib2

bloombergFile = urllib2.urlopen('http://www.bloomberg.com/quote/CCMP:IND','http://www.bloomberg.com/quote/SPX:IND')
bloombergHtml = bloombergFile.read()
bloombergFile.close()

# parse the html using beautiful soap and store in variable `soup`
soup = BeautifulSoup(bloombergHtml)


bloombergAll = soup.find_all("a")
for links in soup.find_all('a'):
    print (links.get('href'))

# query the website and return the html to the variable 'page'
page = urllib2.urlopen('http://www.bloomberg.com/quote/CCMP:IND','http://www.bloomberg.com/quote/SPX:IND') 

# Take out the <div> of name and get its value
name_box = soup.find('h1', attrs={'class': 'name'}) 

# strip() is used to remove starting and trailing
name = name_box.text.strip() 
print name 

# get the index price
price_box = soup.find('div', attrs={'class':'price'}) 
price = price_box.text 
print price

# Python csv module and the datetime module
import csv 
from datetime import datetime

# Extracting multiple indices at the same time. NOT WORKING
bloombergHtml = ['http://www.bloomberg.com/quote/CCMP:IND','http://www.bloomberg.com/quote/SPX:IND']  

# for loop
data = [] 
for pg in quote_page: 
    # query the website and return the html to the variable 'page'
    page = urllib2.urlopen('http://www.bloomberg.com/quote/CCMP:IND','http://www.bloomberg.com/quote/SPX:IND')

    # parse the html using beautiful soap and store in variable `soup`
    soup = BeautifulSoup(bloombergHtml, 'html.parser')

    # Take out the <div> of name and get its value
    name_box = soup.find('h1', attrs={'class': 'name'})
    name = name_box.text.strip() # strip() is used to remove starting and trailing

    # get the index price
    price_box = soup.find('div', attrs={'class':'price'})
    price = price_box.text

    # save the data in tuple
    data.append((name, price))

# open a csv file with append, so old data will not be erased
with open('index.csv', 'a') as csv_file: 
    writer = csv.writer(csv_file)
    # The for loop
    for name, price in data:
        writer.writerow([name, price, datetime.now()])
 

Renkz

Superstar
Supporter
Joined
Jun 12, 2012
Messages
7,814
Reputation
2,310
Daps
18,031
Reppin
NULL
Quick question

I'm messing with python 2.7, and attempted to run a program to scape a site.
@ line 46 (code below) It stated I needed to create an array, which I think is correct.
Yet I keep getting the following error.

Code:
Traceback (most recent call last):
  File "./bloom1.py", line 51, in <module>
    for pg in quote_page: 
NameError: name 'quote_page' is not defined

And suggestions?

Code:
# !/usr/local/bin/python
# python 2
#
# Source code
#
# craw a website (http://www.bloomberg.com/quote/SPX:IND.com), list all url under a specific given path
# To use type in "python" and name of file, then run.

#import libraries
from bs4 import BeautifulSoup
import requests
import urllib2

bloombergFile = urllib2.urlopen('http://www.bloomberg.com/quote/CCMP:IND','http://www.bloomberg.com/quote/SPX:IND')
bloombergHtml = bloombergFile.read()
bloombergFile.close()

# parse the html using beautiful soap and store in variable `soup`
soup = BeautifulSoup(bloombergHtml)


bloombergAll = soup.find_all("a")
for links in soup.find_all('a'):
    print (links.get('href'))

# query the website and return the html to the variable 'page'
page = urllib2.urlopen('http://www.bloomberg.com/quote/CCMP:IND','http://www.bloomberg.com/quote/SPX:IND')

# Take out the <div> of name and get its value
name_box = soup.find('h1', attrs={'class': 'name'})

# strip() is used to remove starting and trailing
name = name_box.text.strip()
print name

# get the index price
price_box = soup.find('div', attrs={'class':'price'})
price = price_box.text
print price

# Python csv module and the datetime module
import csv
from datetime import datetime

# Extracting multiple indices at the same time. NOT WORKING
bloombergHtml = ['http://www.bloomberg.com/quote/CCMP:IND','http://www.bloomberg.com/quote/SPX:IND'] 

# for loop
data = []
for pg in quote_page:
    # query the website and return the html to the variable 'page'
    page = urllib2.urlopen('http://www.bloomberg.com/quote/CCMP:IND','http://www.bloomberg.com/quote/SPX:IND')

    # parse the html using beautiful soap and store in variable `soup`
    soup = BeautifulSoup(bloombergHtml, 'html.parser')

    # Take out the <div> of name and get its value
    name_box = soup.find('h1', attrs={'class': 'name'})
    name = name_box.text.strip() # strip() is used to remove starting and trailing

    # get the index price
    price_box = soup.find('div', attrs={'class':'price'})
    price = price_box.text

    # save the data in tuple
    data.append((name, price))

# open a csv file with append, so old data will not be erased
with open('index.csv', 'a') as csv_file:
    writer = csv.writer(csv_file)
    # The for loop
    for name, price in data:
        writer.writerow([name, price, datetime.now()])
You never init the quote_page array, the only array variable you have is data. Should quote_page be renamed to data?
 

ByAnyMeans

Rookie
Joined
Nov 18, 2016
Messages
197
Reputation
110
Daps
457
Brehs,

I'm a SAS, R, SQL guy with a background in Math and stats.

I'm finding myself having to jump into some c#(C sharp) and access VBA program for work.

How steep is the learning curve and any advice?

I went to udemy and signed up for courses on both fronts btw. I've completed the VBA one and started the c#. The VBA one was so so. The C# one is OK. The object oriented-ness is a little different than SAS and R.
 

levitate

I love you, you know.
Joined
Sep 3, 2015
Messages
38,885
Reputation
5,692
Daps
147,483
Reppin
The Multiverse
StackOverflow is a good source for solving small programming issues.
:ehh:
Working on a Python program for work and kept getting zero returned when dividing.

Apparently (1/16) = 0

:martin:

1/float(16) worked :thumbsup:
 

kevm3

follower of Jesus
Supporter
Joined
May 2, 2012
Messages
16,291
Reputation
5,551
Daps
83,483
StackOverflow is a good source for solving small programming issues.
:ehh:
Working on a Python program for work and kept getting zero returned when dividing.

Apparently (1/16) = 0

:martin:

1/float(16) worked :thumbsup:
Yep, you are dividing two ints together when you do 1/16 in python, and with ints, there are no decimals, so that's why you got zero. By typecasting the 16 to the type of float, which has decimals, you got the correct answer.
 

kevm3

follower of Jesus
Supporter
Joined
May 2, 2012
Messages
16,291
Reputation
5,551
Daps
83,483
I'm going to pick up C# to add to my Javascript. Then, I'll probably look into some functional type of language like Elm. Goal right now is to really dig into server-side programming and then game-programming. Front-end programming is cool, but there's simply way too much change and too many options for me to really want to invest a ton of time into that. Front-end wise, I'll be sticking with Angular 2/Typescript. The addition of types makes it much, much easier to understand what is going on in a program.
 

kevm3

follower of Jesus
Supporter
Joined
May 2, 2012
Messages
16,291
Reputation
5,551
Daps
83,483
What is really annoying about front-end programming is the abundance of frameworks and how rapidly they keep coming out. There was Angular 1, backbone, ember, among others, and now there is Angular 2, CycleJS, react, and vueJS. Then you have to worry about browser compatibility, and it's hard to tell what you can actually use because you have to worry about so many different browsers, and you have to go polyfill the ones that don't have the features you need.

With that said, the front-end is going to be home to some really interesting things in the future with all of the APIs opening up. You can already make 2d or 3d games in browser.

I feel that once you are a full-stack developer, you pretty much have nearly unlimited potential at your hands, being able to make games or applications in which numerous people can all interact with at once. That's my eventual goal.
 

Gmack

Pro
Joined
Mar 29, 2013
Messages
447
Reputation
50
Daps
1,272
Reppin
NULL
This thread is very inspiring.

I've always been the DIY type and really hated spending racks for mods on my sites
 

JahFocus CS

Get It How You Get It
Joined
Sep 10, 2014
Messages
20,462
Reputation
3,754
Daps
82,446
Reppin
Republic of New Afrika
Do you guys master a language before starting to learn a new one?

I'm about 30% of my way through my Python course. Obviously I'll finish it before starting anything else, but should I focus strictly on Python for 6 months to a year? Does it just depend on my competence and comfort with it? (I'm guessing it depends more so on my competence and comfort :laugh:) because I'm also interested in Ruby, C++, and some mobile language. I'm undertaking this coding learning mostly to be able to do mobile apps within the next 3ish years
 

Matt504

YSL as a gang must end
Joined
Sep 7, 2013
Messages
45,083
Reputation
14,687
Daps
272,825
Do you guys master a language before starting to learn a new one?

I'm about 30% of my way through my Python course. Obviously I'll finish it before starting anything else, but should I focus strictly on Python for 6 months to a year? Does it just depend on my competence and comfort with it? (I'm guessing it depends more so on my competence and comfort :laugh:)

I personally haven't mastered any language but I've learned 3 to the level that I can comfortably get work done in a project. I'd say continue focusing on Python and later introduce yourself to other languages.
 

Obreh Winfrey

Truly Brehthtaking
Supporter
Joined
Nov 18, 2016
Messages
20,706
Reputation
25,201
Daps
131,193
So I've got a project for my Operating Systems class where we can pretty much do anything we want related to OS. I'm highly considering using LFS and making my own Linux Distro. Has anyone on here tackled this before? Any tips? What sort of time commitment might I be looking at?
 
Top