小编emp*_*blk的帖子

函数在for循环处停止

当我运行以下代码时,我没有在for循环中获得任何print语句.q永远不会打印出值.但是如果我range在REPL中做了一个并做同样的事情,那就行了.

def main():
    startpoint = 1100000
    qs = range(startpoint, startpoint - 100)
    print("qs = %s" % qs)
    print("Approaching for loop")
    for q in enumerate(qs):
        print("Successfully entered for loop")
        print(q)
    return

if __name__ == "__main__":
    main()
Run Code Online (Sandbox Code Playgroud)

什么阻止上述代码运行?

python range python-3.x

0
推荐指数
1
解决办法
48
查看次数

使用 fetch 函数访问我的 React 应用程序时收到 CORS 错误

连接 API 时,我收到了可怕的 CORS 错误。我正在使用 BeerDB 之一。我尝试了该插件,添加标题,进入index.js但似乎没有解决它。仍在研究它,我的代码App.js如下。这是一个反应应用程序。

我什至可以想到的下一件事是重构我的 API 获取调用以使用axios和使用与当前使用的语法不同的语法。

import React, {useEffect, useState, Component} from 'react';
import './App.css';
import Beer from './Beer.js';

const App = () => {

  const App_Key = "b1322de05886eaf6bdd71b64c52d12b7"

  const [beers, setBeers] = useState([]);

  useEffect (() => {
    getBeers();
   }, []);

  const getBeers = async () => {
    const response = await fetch("http://api.brewerydb.com/v2/?key=b1322de05886eaf6bdd71b64c52d12b7");
    const data = await response.json();
    console.log(data); 
  }

  return(
    <div className="App">  
      <form>
        <input type="text" ></input>
        <button type="submit">Search</button>
      </form> …
Run Code Online (Sandbox Code Playgroud)

cors reactjs node-fetch

0
推荐指数
1
解决办法
3万
查看次数

标签 统计

cors ×1

node-fetch ×1

python ×1

python-3.x ×1

range ×1

reactjs ×1