I have that doubt, in React I don't know what is meant by context, nor provider, nor consumer and of course I don't know how they relate to each other. I have looked in the official React documentation but it is not clear to me.
Mr. Baldan's questions
I have found two answers about it on this site:
- What does .bind(this) work for in Javascript?
- What is the point of using bind(this) in a method in JS?
The problem I see in these answers is that they seem to me to be very focused on the specific use case of the concrete example in which they appear. And they also seem to me that they are not suitable for people like me who are starting (after all, one does not start programming directly with React) On the other hand, if we use good technical documentation such as that of mozilla, I find that I It all seems too technical and abstract. The information I've searched on the internet I think is unclear in the sense that it doesn't explain what problem bind solves . So I wonder if there isn't a super simple explanation that also uses a "Hello World" type example to understand it better.
In the mozilla documentation I mention it says:
The bind() method creates a new function, which when called, assigns its this operator the value given, with a given sequence of arguments preceding any given when the function is called.
The value of this is ignored when the function is called with the new operator.
Let's look at this explanation in parts...
The bind() method creates a new function, which when called, assigns its this operator the given value,
It is not clear to me what this is in relation to bind nor do I know who delivers what to whom, but let's continue...
with a sequence of given arguments preceding any given when the function is called.
I don't know what you mean by "delivered" Who delivers what to whom? And finally:
The value of this is ignored when the function is called with the new operator.
Without understanding what is this
in this movie, they also put this of new
. Why is the lord this
ignored? (With what it has cost me to learn it at this point)
I am making an application with Electron and when I open the developer tools, in the console I get this error:
Uncaught ReferenceError: require is not defined at index.html:11
According to a certain English stackoverflow question , I am supposed to have Node integration enabled in my index.js from which electron bootstrap:
let win = new BrowserWindow({ width: 2200, height: 1200, title: "Contact Remember", maximizable: true, center: true, frame: true, show: true, webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
}});
Which is the attribute nodeIntegration: true
. However this doesn't work for me
According to this other question in English you could use the following resources:
Browserify: Most Node modules can be used in the browser
Webpack: Does everything (packages JavaScript code, CSS, etc.). It was made popular by the rise of React, but is known for its steep learning curve.
Rollup - Take advantage of ES6 modules
I don't want to use any of the above 3 options, because I know that this error will be corrected without using them, because I did it before, although I don't remember how I did it anymore.
First of all I want to say that although this question seems to be a duplicate of this other one I think they do not deal with the same thing and I think that the problem of that other question is different from mine. In any case, I think that one more explanation for this type of error would be enriching for the community.
import sys
sys.path.append("../CREDENTIALS")
sys.path.append("./SDK")
import consts
import client
import account_api as account
import futures_api as future
import lever_api as lever
import spot_api as spot
import swap_api as swap
import index_api as index
import option_api as option
import system_api as system
import information_api as information
import json
import datetime
import TOKENS
These imports are at the beginning of myprogram.py. This is my error message: PS C:\MYPROJECTPATH\MYPROJECT> python .\myprogram.py Traceback (most recent call last): File "C:\MYPROJECTPATH\MYPROJECT\myprogram.py", line 5, in import client File "./SDK\client.py", line 3, in from . import consts as c, utils, exceptions ImportError: attempted relative import with no known parent package
I am trying to use firebase hosting. I have put in the console: npm install -g firebase-tools
. Now I put firebase login
in and the console tells me:
"firebase" is not recognized as an internal or external command, program or executable batch file.
How do I fix this so that the console recognizes the term "firebase" for me?
The question arose when I saw the definition of Docker on wikipedia in its article in English . The following sentence caught my attention:
All containers are run by a single operating system kernel and are thus more lightweight than virtual machines.
which translated is:
All containers are run by a single operating system kernel and are therefore lighter than virtual machines.
I used to think that they were the same, but in the sentence it can be seen that a distinction is made.
I'm making a game and I corrected some bugs in a branch that I created especially for it called "FixBugs", I made a commit in said branch when I managed to correct them. But I get the following message when I want to do the push:
fatal: The current branch FixBugs has no upstream branch
What does this mean?
I want to put the text of a .txt in a variable. I have found the following code:
var client = new XMLHttpRequest();
client.open('GET', '/foo.txt');
client.onreadystatechange = function() {
alert(client.responseText);
}
client.send();
Now I modify it as follows:
var client = new XMLHttpRequest();
var chaintext = client.open('GET', '/foo.txt');
client.onreadystatechange = function() {
alert(client.responseText);
}
client.send();
console.log(chaintext);
I create a .txt with a phrase in the folder C:\Users\USER\Downloads
But nothing... The console tells me "undefined". I suppose that there are several things that may be failing: to begin with, the path is wrong or the directory to which the browser is pointing is something else. Does anyone know how I can write a code that opens a .txt from a specific path?
I have the following dictionary:
diccionario = {1: "uno", 2: "dos", 3: "tres"}
I would like to see if it contains a certain key, for example the 2. How can I find out?
And by the way... I would also like to know how to check if a value is in the dictionary. How do you give it a value and get a key back?
i want to use colors in my python terminal output format for print function. I have tried the following codes:
from colorama import Fore, Back, Style
print('\033[1;41mHighlighted Red like Radish\033[1;m')
print('\x1b[6;30;42m' + 'Success!' + '\x1b[0m')
prt = "Hello world!"
print("\033[94m {}\033[00m" .format(prt))
print("\033[1;32;40m Bright Green \n")
print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background')
print(Style.DIM + 'and in dim text')
print(Style.RESET_ALL)
print('back to normal now')
As you can see I have also tried importing the colorama module but nothing. On the internet, googling there seems to be a lot of information about it, the problem is that it seems a bit outdated because print is no longer an instruction but a function. My python version is 3.4.4 and my IDLE version is 3.4.3
Thank you very much in advance.
be the following code of a simple app in kivy:
from kivy.config import Config
Config.set('kivy', 'keyboard_mode', 'system')
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.properties import StringProperty
Builder.load_file('design2.kv')
class MyWidget(BoxLayout):
def __init__(self):
super(MyWidget, self).__init__()
self.showtext() #Llamamos al método desde el constructor
def showtext(self):
with open("Prueba.txt","r") as f:
self.ids['Label1'].text = f.read()
class myApp(App):
def build(self):
return MyWidget()
def on_pause(self):
return True
def on_resume(self):
pass
if __name__ in ('__main__', '__android__'):
myApp().run()
Let the .kv file be (not relevant here, though):
<MyWidget>:
BoxLayout:
Label:
id: Label1
I am wondering about the following code snippet from the first code:
class MyWidget(BoxLayout):
def __init__(self):
super(MyWidget, self).__init__()
self.showtext() #Llamamos al método desde el constructor
As I understand it, def __init__(self):
it is a constructor. What is a constructor for? The other question is about the line: super(MyWidget, self).__init__()
What is super
?
based on the example of this question I want to make a program that shows me a text saved in a variable, "g". Here goes the code:
# config
from kivy.config import Config
Config.set('kivy', 'keyboard_mode', 'system') #¿Para qué sirve esta línea?
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
from kivy.lang import Builder
from kivy.clock import Clock
from itertools import cycle
import random
Builder.load_file('design.kv')
class MyWidget(BoxLayout):
random_number = StringProperty()
string = StringProperty()
def __init__(self):
super(MyWidget, self).__init__()
self.random_number = str(random.randint(1, 100))+'\n'
self.listText = cycle(('Hola', 'soy', 'una', 'etiqueta'))
Clock.schedule_interval(self.change_label_text, 0.6) #¿Para qué sirve esta línea?
def numero_aleatorio(self):
self.random_number += str(random.randint(1, 100))+'\n'
def change_label_text(self, *args):
self.string = next(self.listText)
class myApp(App):
def build(self):
return MyWidget()
def on_pause(self): #¿Para qué sirve esta función?
return True
def on_resume(self): #¿Para que sirve esta función?
pass
g = "Esto es un mensaje guardado en una variable" #Aquí está la variable que guarda el texto que quiero mostrar
if __name__ in ('__main__', '__android__'): #¿Para qué sirve esta línea?
myApp().run()
And the file design.kv
:
<MyWidget>:
BoxLayout:
TextInput:
id: textInp2
text: g
multiline: True
readonly: True
background_color: 0.92,0.89,0.75,1
on_focus: self.focus = False
Running it gives me an error: NameError: name 'g' is not defined
How can I make it show me the variable g?
suppose I have the simplest program that can be done with kivy:
from kivy.app import App
from kivy.uix.button import Button
class TestApp(App):
def build(self):
return Button(text='Hello World')
TestApp().run()
In addition to seeing it on my desktop computer, I would like to see it on my mobile. What steps should I take?
I would like to background a program that I have in my startup folder, so that it runs when I log in to windows. I have tried to use the nircmd program but I don't see how I can do it. Also when I put: Nircmd win hide ititle "programa""
in the windows cmd I get a message that tells me that Nircmd is not a valid win32 application. The truth is that I have not found practically anything on your website . By the way, I already ask if there is something that can be done in this sense with Python.
OS: WXP SP3
Python: 3.4.4
Thank you very much for your help and happy new year.
I have made the following program (with your help) that prints in a file all the paths of the files and folders that a given path contains:
from os import walk, getcwd
def ls(ruta = getcwd()):
for root, subdirs, archivos in walk(ruta):
f = open("ficheroderutas.txt","a",encoding="utf8")
for archivo in archivos:
f.write(root+'\\'+archivo+"\n")
for subdir in subdirs:
f.write(root+'\\'+subdir+"\n")
f.close()
return
The problem I have is that when I put: ls(ruta='C:\\')
since I want to save all the paths to files and folders on my hard drive in a file, it takes me several minutes to do this task (generating a txt file of almost 30MB). I was wondering if there is a faster way to run this code or any other. I am not looking to change the code, unless it is to take advantage of features of a library that allows parallelization, something similar to the fork of c... I suppose it will exist. Because this last point is important since I have several cores in my computer. Well, the answer could be very extensive or not so long. Basically the options that sound to me are:
- generate an .exe of my program, since I suppose that if it were written in already compiled machine code to give it to the micro, it would run faster than executing it through the interpreter.
- Translate it c, preferably with a python->c translator (that's what it's called, right?), although I suppose the problem is that automating this type of program rewriting tasks doesn't result in code as efficient as if you rewritten it yourself.
- Use some python library that allows me to parallelize my code.
Does anyone know if there is any other option? I don't know if there is any other option. If the parallelization library exists, what is it called?
OS: WXP SP3
Python 3.4.4
I want to convert a string to a list without separating the characters. I can do:
cadena = "hola"
If now I do:
list(cadena)
The interpreter's response is:
['h', 'o', 'l', 'a']
But suppose I want to have this other response:
['hola']
How can I do it without doing: lista = ["hola"]
? Is there something like a function that joins all the separated characters in a list to a list of a single string? Or a function that joins me all the elements, whether numbers or strings, of a list and presents them to me as a string of a list of a single element, that element being said string?
I'm having trouble importing a function:
def helloworld():
print("Hello World!")
I have it in a file called hello.py inside the folder: C:/projects.
I enter the following:
>>> import sys
>>> sys.path.append('C:/proyectos')
>>> import hello
>>> helloworld()
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
helloworld()
NameError: name 'helloworld' is not defined
I don't understand why it gives me this error if I have defined the helloworld function inside the hello.py file. Does anyone know how to import a function that you have created inside a .py file?
Thank you very much for your help
I want to update my python pip to the latest version. Does anyone know what is the command that I must enter in the windows cmd? Thank you very much.
I am trying to use the scandir module and it gives me the error: ImportError: cannot import name 'scandir' . I don't understand it, the version I'm using, 3.4.4, is supposed to already have this module implemented. Does anyone have an idea how I can fix it? Thank you very much.
I'm trying to make a function where you pass a list and an index and it returns another list that contains the element from the first list you passed to it that belongs to the place of the index you passed to it. I have written something like this:
def indextoentry(lista,index):
listresult = []
listresult = listresult + lista[index]
return(listresult)
As you may already know this gives a type mismatch error on the line listresult = listresult + lista[index]
So I try something else using the append() method:
def indextoentry(lista,index):
listresult = []
listresult = listresult.append(lista[index])
return(listresult)
This does not give me an error but it gives me 'None'
if I do>>> print(indextoentry([1,2,3],1))
How can I get my function to return a list? Thank you very much in advance.