SOLUTION IS :
Maximum execution time of 30 seconds exceeded in wp-includes\class-http.php (fatal error)
Fatal error: Maximum execution time of 30 seconds exceeded in htdocs\wp-includes\class-http.php on line 1402 SOLUTION IS : This is due...
Berbagi apapun yang saya tahu, berbagi tentang pendidikan, teknologi, website, dan lainnya.
Fatal error: Maximum execution time of 30 seconds exceeded in htdocs\wp-includes\class-http.php on line 1402 SOLUTION IS : This is due...
$items = array( 'orange', 'pear', 'banana' );
# without indexes
foreach ( $items as $item )
echo $item;
# with indexes
foreach ( $items as $i => $item )
echo $i, $item;
items = ['orange', 'pear', 'banana']
# without indexes
for item in items:
print item
# with indexes
for (i, item) in enumerate(items):
print i, item
$continents = array(
'africa' => 'Africa',
'europe' => 'Europe',
'north-america' => 'North America'
);
# without keys
foreach ( $continents as $continent )
echo $continent;
# with keys
foreach ( $continents as $slug => $title )
echo $slug, $title;
continents = {
'africa': 'Africa',
'europe': 'Europe',
'north-america': 'North America'
}
# without keys
for continent in continents.values():
print continent
# with keys
for (slug, title) in continents.items():
print slug, title
help([]). It’s a lot faster than googling for documentation.One of the first problems I had when learning Python was looping over data. PHP’s arrays are very versatile, but in Python, you need to thi...
HYDRATE_ARRAY - This will return you an array of records that are represented by another array:$q = Doctrine_Query::create()
->from('Post p')
->setHydrationMode(Doctrine::HYDRATE_ARRAY);
$resultSet = $q->execute(); // $resultSet is an array
foreach ($resultSet as $post) {
// $post is an array
echo $post['title'];
}
HYDRATE_RECORD - This will return you an collection (Doctrine_Collection) of objects:$q = Doctrine_Query::create()
->from('Post p')
->setHydrationMode(Doctrine::HYDRATE_RECORD); // Unnecessary, HYDATE_RECORD is default method
$resultSet = $q->execute(); // $resultSet is an Doctrine_Collection object
foreach ($resultSet as $post) {
// $post is an Post object
echo $post->getTitle();
echo $post['title']; // Each Doctrine's Model object implements ArrayAccess interface so this is possible
echo $post->myCustomMethod();
}
HYDRATE_SINGULAR_SCALAR - Will return the value of first column of query's result: $q = Doctrine_Query::create()
->select('p.created_at')
->from('Post p')
->where('p.id = ?', 321)
->setHydrationMode(Doctrine::HYDRATE_SINGULAR_SCALAR);
$createdAt = $q->execute(); // $createdAt has value of first column from first record from result set (eg.: 2008-04-06 21:22:35)
Data Hydrators Doctrine has a concept of data hydrators for transforming your :php:class:`Doctrine_Query` instances to a set of PHP dat...
Movies Recommendation : MovieLens - Movie Recommendation Data Sets http://www.grouplens.org/node/73 Yahoo! - Movie, Music, and Images...
python at the Unix command prompt.python2.4, python2.5, python2.6 or python2.7, rather than python, depending on your machine.[cs188-ta@nova ~]$ python
Python 2.6.5 (r265:79063, Jan 14 2011, 14:20:15)
[GCC 4.4.1] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>>>>>) they will be evaluated and the result will be returned on the next line.>>> 1 + 1
2
>>> 2 * 3
6True and False values.>>> 1==0
False
>>> not (1==0)
True
>>> (2==2) and (2==3)
False
>>> (2==2) or (2==3)
True+ operator is overloaded to do string concatenation on string values.>>> 'artificial' + "intelligence"
'artificialintelligence'>>> 'artificial'.upper()
'ARTIFICIAL'
>>> 'HELP'.lower()
'help'
>>> len('Help')
4' ' or double quotes " " to surround string. This allows for easy nesting of strings.>>> s = 'hello world'
>>> print s
hello world
>>> s.upper()
'HELLO WORLD'
>>> len(s.upper())
11
>>> num = 8.0
>>> num += 2.5
>>> print num
10.5dir and help commands:>>> s = 'abc'
>>> dir(s)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__','__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__','__repr__', '__rmod__', '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind','rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
>>> help(s.find)Help on built-in function find:
find(...)
S.find(sub [,start [,end]]) -> int
Return the lowest index in S where substring sub is found,
such that sub is contained within s[start,end]. Optional
arguments start and end are interpreted as in slice notation.
Return -1 on failure.
>> s.find('b')
1dir (ignore those with underscores '_' around the method name).>>> fruits = ['apple','orange','pear','banana']
>>> fruits[0]
'apple'+ operator to do list concatenation:>>> otherFruits = ['kiwi','strawberry']
>>> fruits + otherFruits
>>> ['apple', 'orange', 'pear', 'banana', 'kiwi', 'strawberry']fruits[-1] will access the last element 'banana':>>> fruits[-2]
'pear'
>>> fruits.pop()
'banana'
>>> fruits
['apple', 'orange', 'pear']
>>> fruits.append('grapefruit')
>>> fruits
['apple', 'orange', 'pear', 'grapefruit']
>>> fruits[-1] = 'pineapple'
>>> fruits
['apple', 'orange', 'pear', 'pineapple']fruits[1:3], returns a list containing the elements at position 1 and 2. In general fruits[start:stop] will get the elements in start, start+1, ..., stop-1. We can also do fruits[start:] which returns all elements starting from the start index. Also fruits[:end] will return all elements before the element at position end:>>> fruits[0:2]
['apple', 'orange']
>>> fruits[:3]
['apple', 'orange', 'pear']
>>> fruits[2:]
['pear', 'pineapple']
>>> len(fruits)
4>>> lstOfLsts = [['a','b','c'],[1,2,3],['one','two','three']]
>>> lstOfLsts[1][2]
3
>>> lstOfLsts[0].pop()
'c'
>>> lstOfLsts
[['a', 'b'],[1, 2, 3],['one', 'two', 'three']]dirand get information about them via the help command:>>> dir(list)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
'__delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__',
'__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__',
'__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__',
'__rmul__', '__setattr__', '__setitem__', '__setslice__', '__str__',
'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse',
'sort']>>> help(list.reverse)
Help on built-in function reverse:
reverse(...)
L.reverse() -- reverse *IN PLACE*
>>> lst = ['a','b','c']
>>> lst.reverse()
>>> ['c','b','a']>>> pair = (3,5)
>>> pair[0]
3
>>> x,y = pair
>>> x
3
>>> y
5
>>> pair[1] = 6
TypeError: object does not support item assignment>>> shapes = ['circle','square','triangle','circle']
>>> setOfShapes = set(shapes)
>>> setOfShapes
set(['circle','square','triangle'])
>>> setOfShapes.add('polygon')
>>> setOfShapes
set(['circle','square','triangle','polygon'])
>>> 'circle' in setOfShapes
True
>>> 'rhombus' in setOfShapes
False
>>> favoriteShapes = ['circle','triangle','hexagon']
>>> setOfFavoriteShapes = set(favoriteShapes)
>>> setOfShapes - setOfFavoriteShapes
set(['square','polyon'])
>>> setOfShapes & setOfFavoriteShapes
set(['circle','triangle'])
>>> setOfShapes | setOfFavoriteShapes
set(['circle','square','triangle','polygon','hexagon'])>>> studentIds = {'knuth': 42.0, 'turing': 56.0, 'nash': 92.0 }
>>> studentIds['turing']
56.0
>>> studentIds['nash'] = 'ninety-two'
>>> studentIds
{'knuth': 42.0, 'turing': 56.0, 'nash': 'ninety-two'}
>>> del studentIds['knuth']
>>> studentIds
{'turing': 56.0, 'nash': 'ninety-two'}
>>> studentIds['knuth'] = [42.0,'forty-two']
>>> studentIds
{'knuth': [42.0, 'forty-two'], 'turing': 56.0, 'nash': 'ninety-two'}
>>> studentIds.keys()
['knuth', 'turing', 'nash']
>>> studentIds.values()
[[42.0, 'forty-two'], 56.0, 'ninety-two']
>>> studentIds.items()
[('knuth',[42.0, 'forty-two']), ('turing',56.0), ('nash','ninety-two')]
>>> len(studentIds)
3dir and help to learn about the functions you can call on dictionaries.for loop. Open the file called foreach.py and update it with the following code:# This is what a comment looks like
fruits = ['apples','oranges','pears','bananas']
for fruit in fruits:
print fruit + ' for sale'
fruitPrices = {'apples': 2.00, 'oranges': 1.50, 'pears': 1.75}
for fruit, price in fruitPrices.items():
if price < 2.00:
print '%s cost %f a pound' % (fruit, price)
else:
print fruit + ' are too expensive!'
foreach.py:[cs188-ta@nova ~/tutorial]$ python foreach.py
apples for sale
oranges for sale
pears for sale
bananas for sale
oranges cost 1.500000 a pound
pears cost 1.750000 a pound
apples are too expensive!if and else) in Python, check out the official Python tutorial section on this topic.map and filter:>>> map(lambda x: x * x, [1,2,3])
[1, 4, 9]
>>> filter(lambda x: x > 3, [1,2,3,4,5,4,3,2,1])
[4, 5, 4]lambda if you're interested.nums = [1,2,3,4,5,6] plusOneNums = [x+1 for x in nums] oddNums = [x for x in nums if x % 2 == 1] print oddNums oddNumsPlusOne = [x+1 for x in nums if x % 2 ==1] print oddNumsPlusOne
listcomp.py, which you can run:[cs188-ta@nova ~]$ python listcomp.py
[1,3,5]
[2,4,6]listcomp2.py.if 0 == 1:
print 'We are in a world of arithmetic pain'
print 'Thank you for playing'
Thank you for playingif 0 == 1:
print 'We are in a world of arithmetic pain'
print 'Thank you for playing'
fruitPrices = {'apples':2.00, 'oranges': 1.50, 'pears': 1.75}
def buyFruit(fruit, numPounds):
if fruit not in fruitPrices:
print "Sorry we don't have %s" % (fruit)
else:
cost = fruitPrices[fruit] * numPounds
print "That'll be %f please" % (cost)
# Main Function
if __name__ == '__main__':
buyFruit('apples',2.4)
buyFruit('coconuts',2)
main function as in Java, the __name__ == '__main__' check is used to delimit expressions which are executed when the file is called as a script from the command line. The code after the main check is thus the same sort of code you would put in a main function in Java.[cs188-ta@nova ~]$ python fruit.py
That'll be 4.800000 please
Sorry we don't have coconutsquickSort function in Python using list comprehensions. Use the first element as the pivot. You can find the solution in quickSort.py.FruitShop:class FruitShop:
def __init__(self, name, fruitPrices):
"""
name: Name of the fruit shop
fruitPrices: Dictionary with keys as fruit
strings and prices for values e.g.
{'apples':2.00, 'oranges': 1.50, 'pears': 1.75}
"""
self.fruitPrices = fruitPrices
self.name = name
print 'Welcome to the %s fruit shop' % (name)
def getCostPerPound(self, fruit):
"""
fruit: Fruit string
Returns cost of 'fruit', assuming 'fruit'
is in our inventory or None otherwise
"""
if fruit not in self.fruitPrices:
print "Sorry we don't have %s" % (fruit)
return None
return self.fruitPrices[fruit]
def getPriceOfOrder(self, orderList):
"""
orderList: List of (fruit, numPounds) tuples
Returns cost of orderList. If any of the fruit are
"""
totalCost = 0.0
for fruit, numPounds in orderList:
costPerPound = self.getCostPerPound(fruit)
if costPerPound != None:
totalCost += numPounds * costPerPound
return totalCost
def getName(self):
return self.name
FruitShop class has some data, the name of the shop and the prices per pound of some fruit, and it provides functions, or methods, on this data. What advantage is there to wrapping this data in a class?FruitShop implementation inshop.py. We then import the code from this file (making it accessible to other scripts) using import shop, since shop.py is the name of the file. Then, we can create FruitShop objects as follows:import shop
shopName = 'the Berkeley Bowl'
fruitPrices = {'apples': 1.00, 'oranges': 1.50, 'pears': 1.75}
berkeleyShop = shop.FruitShop(shopName, fruitPrices)
applePrice = berkeleyShop.getCostPerPound('apples')
print applePrice
print('Apples cost $%.2f at %s.' % (applePrice, shopName))
otherName = 'the Stanford Mall'
otherFruitPrices = {'kiwis':6.00, 'apples': 4.50, 'peaches': 8.75}
otherFruitShop = shop.FruitShop(otherName, otherFruitPrices)
otherPrice = otherFruitShop.getCostPerPound('apples')
print otherPrice
print('Apples cost $%.2f at %s.' % (otherPrice, otherName))
print("My, that's expensive!")
shopTest.py; you can run it like this:[cs188-ta@nova ~]$ python shopTest.py Welcome to the Berkeley Bowl fruit shop 1.0 Apples cost $1.00 at the Berkeley Bowl. Welcome to the Stanford Mall fruit shop 4.5 Apples cost $4.50 at the Stanford Mall. My, that's expensive!
import shop statement told Python to load all of the functions and classes in shop.py. The line berkeleyShop = shop.FruitShop(shopName, fruitPrices) constructs an instance of the FruitShop class defined in shop.py, by calling the __init__ function in that class. Note that we only passed two arguments in, while __init__ seems to take three arguments: (self, name, fruitPrices). The reason for this is that all methods in a class have self as the first argument. The self variable's value is automatically set to the object itself; when calling a method, you only supply the remaining arguments. The self variable contains all the data (name andfruitPrices) for the current specific instance (similar to this in Java). The print statements use the substitution operator (described in the Python docs if you're curious).person_class.py containing the following code:class Person:
population = 0
def __init__(self, myAge):
self.age = myAge
Person.population += 1
def get_population(self):
return Person.population
def get_age(self):
return self.age
[cs188-ta@nova ~]$ python person_class.py>>> import person_class
>>> p1 = person_class.Person(12)
>>> p1.get_population()
1
>>> p2 = person_class.Person(63)
>>> p1.get_population()
2
>>> p2.get_population()
2
>>> p1.get_age()
12
>>> p2.get_age()
63age is an instance variable and population is a static variable. population is shared by all instances of the Person class whereas each instance has its own age variable.range to generate a sequence of integers, useful for generating traditional indexed forloops:for index in range(3):
print lst[index]
reload command:
>>> reload(shop)import, do not include the ".py" from the filename.import shopimport shop.pyMODULE NAME.MEMBER NAME, where MODULE NAME is the name of the .py file, and MEMBER NAME is the name of the variable (or function) you are trying to access.for loop matches the number of elements in each item of the list. Similarly for working with tuples.pair is a tuple of two elements (e.g. pair =('apple', 2.0)) then the following code would cause the "too many values to unpack error":(a,b,c) = pairfor loop:pairList = [('apples', 2.00), ('oranges', 1.50), ('pears', 1.75)]
for fruit, price, color in pairList:
print '%s fruit costs %f and is the color %s' % (fruit, price, color)
len(NAME OF LIST).reload(YOUR_MODULE) to guarantee your changes are being reflected. reload works similarly to import.Python Basics Required Files You can download all of the files associated with the Python mini-tutorial as a zip archive: python_basics...
As you can see it found a few open ports and listed the services that are run on them. Below I have a list of some of the most popular ports...
I figured it out!
The Visual Studio installer must have added an errant line to the registry.
open up
regedit and take a look at this registry key:
See that key? The Content Type key? change its value from text/plain to text/javascript.
Finally chrome can breathe easy again.
I should note that neither Content Type nor PercievedType are there by default on Windows 7, so you could probably safely delete them both, but the minimum you need to do is that edit.
Anyway I hope this fixes it for you too!
|
I figured it out! The Visual Studio installer must have added an errant line to the registry. open up regedit and take a look at...