I have been looking for an answer for almost a week now, but having read all the stackoverflow items i can't seem to find a solution that is working for me.
The error that i'm having is :
Port: Could not establish connection. Receiving end does not exist. lastError:30 set lastError:30 dispatchOnDisconnect messaging:277
folder layout :
img
developer_icon.png
js
sidebar.js
main.js
jquery-2.0.3.js
manifest.json
my the manifest.json file looks something like this (it is version 2) :`
"browser_action": {
"default_icon": "./img/developer_icon.png"
},
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["./js/sidebar.js"],
"run_at": "document_end"
}
],
"background" : {
"scripts" : ["./js/main.js","./js/jquery-2.0.3.js"]
},
I want to handle the user clicking the extension icon so i could inject a sidebar in the existing website (because the extension i would like to develop requires that amount of space). So in main.js :
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.getSelected(null, function(tab){
chrome.tabs.sendMessage(
//Selected tab id
tab.id,
//Params inside a object data
{callFunction: "toggleSidebar"},
//Optional callback function
function(response) {
console.log(response);
}
);
});
});
and in sidebar.js :
chrome.runtime.onMessage.addListener(function(req,sender,sendResponse){
console.log("sidebar handling request");
toggleSidebar();
});
but i'm never able to see the console.log in my console because of the error. Does someone know what i did wrong?
Thanks in advance!
hi;
i need grab to internet explorer address bar. how to get address bar url for python ? (i need second part other browsers grabbing address bar but internet explorer is urgently).
Thanks.
Which technology is better to use in terms of performance for high performance scalable web application? PHP or Python?
The project is going to involve database.
I want to parse a html-page that unfortunately requires JavaScript to show any content. In order to do so I use a small python-script that pulls the html-code of the page, but after that I have to execute the JavaScript in a DOM-context which seems pretty hard.
To make it even harder I want to use it in a server environment that has no X11-server.
Note: I already read about http://code.google.com/p/pywebkitgtk/ but it seems to need a X-server.
Python
params = urllib.parse.urlencode({'spam': '1', 'eggs': '2', 'bacon': '3'})
binary_data = params.encode('utf-8')
reg = urllib.request.Request("http://www.abc.com/abc/smart/ap/request/",binary_data)
reg.add_header('Content-Type','application/x-www-form-urlencoded')
f = urllib.request.urlopen(reg)
print(f.read())
PHP
if($_SERVER['REQUEST_METHOD'] == 'POST') {
//parse_str($_SERVER['QUERY_STRING']);
var_dump($_SERVER['QUERY_STRING']);
}
When i try print binary_data , it does show the parameter but by the time it reaches the PHP , i see nothing.
Any idea?
What is the proper indentation for Python multiline strings within a function?
def method:
string = """line one
line two
line three"""
or
def method:
string = """line one
line two
line three"""
or something else?
It looks kind of weird to have the string hanging outside the function in the first example.
Thanks.
I'm looking for a quick bash script or program that will allow me to kick off a python script in a separate process. What's the best way to do this? I know this is incredibly simple, just curious if there's a preferred way to do it.
Hi,
How can i print only certain words from a string in python ?
lets say i want to print only the 3rd word (which is a number) and the 10th one
while the text length may be different each time
mystring = "You have 15 new messages and the size is 32000"
thanks.
How can I split a line in Python at a non-printing ascii character (such as the long minus sign hex 0x97 , Octal 227)?
I won't need the character itself. The information after it will be saved as a variable.
How can I log into my Launchpad account in a python script? Any sample code would be appreciated.
The login url is https://launchpad.net/+login and then redirect to something like https://login.launchpad.net/fJLVSRbxPfKTpVDr/+decide
Thanks in advance!
Is there any short way to achieve what APT does in Python ?
I mean, when the package manager prompts a yes/no question followed by "[Yes/no]".
The scripts accepts YES/Y/yes/y or "enter" (defaults to Yes as hinted by the capital)
The only thing I find in the official doc is input/raw_input..
I know it's not that hard to emulate, but it's annoying to rewrite :|
Well i'm learning Python cuz' i think is an awesome and powerful language like C++, perl or C# but is really really easy at same time. I'm using JetBrains' Pycharm and when i define a function it ask me to add a "Documentation String Stub" when i click yes it adds somethin like this:
"""
"""
so the full code of the function is something like this:
def otherFunction(h, w):
"""
"""
hello = h
world = w
full_word = h + ' ' + w
return full_word
I would like to know what these (""" """) symbols means, Thanks.
Ps.Data: Sorry for my bad english :D
Hi
i am new to python
i am trying to extract the text between that has specific text file
----
data1
data1
data1
extractme
----
data2
data2
data2
----
data3
data3
extractme
----
and then dump it to text file so that
----
data1
data1
data1
extractme
---
data3
data3
extractme
---
thanks for the help
data1
data1
I'm curious if their is some python magic I may not know to accomplish a bit of frivolity
given the line:
csvData.append(','.join([line.split(":").strip() for x in L]))
I'm attempting to split a line on :, trim whitespace around it, and join on ,
problem is, since the array is returned from line.split(":"), the
for x in L #<== L doesn't exist!
causes issues since I have no name for the array returned by line.split(":")
So I'm curious if there is a sexy piece of syntax I could use to accomplish this in one shot?
Cheers!
What's the best way to sanitise user input for a Python-based web application? Is there a single function to remove HTML characters and any other necessary characters combinations to ensure that an XSS or SQL injection attack isn't possible?
This is a question I have wondered about for quite some time, yet I have never found a suitable solution. If I run a script and I come across, let's say an IndexError, python prints the line, location and quick description of the error and exits. Is it possible to automatically start pdb when an error is encountered? I am not against having an extra import statement at the top of the file, nor a few extra lines of code.
Hello,
I've been having problems with the infoWindows and Google Maps API v3.
Initially, I've ran into the problem that everyone else has of closing infoWindows when opening a new one.
I thought to have solved the problem by defining "infowindow" beforehand. Now they close when I click on a new marker, but the content is the same.
How should I re-structure my code to make sure the content is the right one each time - and only one infoWindow is open at a given time?
Thank you!
Paul
var allLatLngs = new Array();
var last = 0;
var infowindow;
function displayResults(start, count){
if(start === undefined){
start = last;
}
if(count === undefined){
count = 20;
}
jQuery.each(jsresults, function(index, value) {
if(index >= start && index < start+count){
var obj = jQuery.parseJSON(value);
$("#textresults").append(index + ": <strong>" + obj.name + "</strong> " + Math.round(obj.distanz*100)/100 + " km entfernt" + "<br/>");
var myLatlng = new google.maps.LatLng(obj.geo_lat, obj.geo_lon);
allLatLngs.push(myLatlng);
var contentString = '<strong>'+obj.name+'</strong>';
infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: myLatlng,
//title:"Hello World!"
});
marker.setMap(map);
google.maps.event.addListener(marker, 'click', function() {
if (infowindow) { infowindow.close(map,marker); }
infowindow.open(map,marker);
});
}
});
last = start+count;
Does anybody know any module in Python that computes the best bipartite matching?
I have tried the following two:
munkres
hungarian
However, in my case, I have to deal with non-complete graph (i.e., there might not be an edge between two nodes), and therefore, there might not be a match if the node has no edge. The above two packages seem not to be able to deal with this.
Any advice?
In python if a string contains the following,
print valid_str
The output of this is
Record is positive in tone:
It emphasizes "what a child can do and his or her achievements, as opposed to what he or she cannot do," explains the It is useful for progress and achievements during office conferences
How to search for the pattern It is useful in the above string and if not found return something.
Thanks..
What is the shortest / most elegant way to implement the following Scala code with an abstract attribute in Python?
abstract class Controller {
val path: String
}
A subclass of Controller is enforced to define "path" by the Scala compiler. A subclass would look like this:
class MyController extends Controller {
override val path = "/home"
}
In Python I can use the iterkeys() method to iterate over the keys of a dictionary. For example:
mydict = {'a': [3,5,6,43,3,6,3,],
'b': [87,65,3,45,7,8],
'c': [34,57,8,9,9,2],}
for k in mydict.iterkeys():
print k
gives me:
a
c
b
How can I do something similar in Javascript?
I have an unknown number of functions in my python script (well, it is known, but not constant) that start with site_...
I was wondering if there's a way to go through all of these functions in some main function that calls for them.
something like:
foreach function_that_has_site_ as coolfunc
if coolfunc(blabla,yada) == true:
return coolfunc(blabla,yada)
so it would go through them all until it gets something that's true.
thanks!