当您创建一个新对象时,它会立即成为主对象的一部分。我是 Blender 的新手,如何创建一个与现有对象无关的新对象?
(Cntrl + J)
- 没有帮助。
(Shift + A)
- 没有帮助。
问题在于重新点击,考虑到对象不是一个(因此它们的颜色不同),如何保存和恢复对象的颜色。比如两个盒子:黄色和蓝色,我们把两者的颜色都改成黑色,如何恢复它们原来的颜色呢?
using System.Collections.Generic;
using UnityEngine;
public class VisualRay : MonoBehaviour
{
public UnityEngine.UI.Selectable CurrentSelectable;
private Color color;
void LateUpdate()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.DrawRay(transform.position, transform.forward*100f, Color.yellow);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
GameObject selectable = hit.collider.gameObject;
if ((selectable.tag == "Box") && (Input.GetKeyDown(KeyCode.F)))
{
color = selectable.GetComponent<Renderer>().material.color;
selectable.GetComponent<Renderer>().material.color = Color.red;
}
}
}
}
我试过这样,但没有奏效:
using System.Collections.Generic;
using UnityEngine;
public class VisualRay : MonoBehaviour
{
public Transform Pointer;
public UnityEngine.UI.Selectable CurrentSelectable;
private Color color;
bool Transform_color = false;
void LateUpdate()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.DrawRay(transform.position, transform.forward*100f, Color.yellow);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Pointer.position = hit.point;
GameObject selectable = hit.collider.gameObject;
if ((selectable.tag == "Box") && (Input.GetKeyDown(KeyCode.F)))
{
if (Transform_color == false)
{
color = selectable.GetComponent<Renderer>().material.color;
selectable.GetComponent<Renderer>().material.color = Color.red;
Transform_color = true;
}
else
{
selectable.GetComponent<Renderer>().material.color = color;
}
}
}
}
}
我知道暴露一整段代码并要求解析它是不正确的,但我无法理解它是如何工作的,我浏览了 C# 教科书上的基础,部分理解它是什么样的,但是 C# for团结是非常不同的......
public class FPSInput : MonoBehaviour {
public float speed = 6.0f;
public float gravity = -9.8f;
private CharacterController _charController;
void Start() {
_charController = GetComponent<CharacterController>();
}
void Update() {
float deltaX = Input.GetAxis("Horizontal") * speed;
float deltaZ = Input.GetAxis("Vertical") * speed;
Vector3 movement = new Vector3(deltaX, 0, deltaZ);
movement = Vector3.ClampMagnitude(movement, speed);
movement.y = gravity;
movement *= Time.deltaTime;
movement = transform.TransformDirection(movement);
_charController.Move(movement);
}
using UnityEngine;
using System.Collections;
public class MouseLook : MonoBehaviour
{
public enum RotationAxes
{
MouseXAndY = 0,
MouseX = 1,
MouseY = 2
}
{
public RotationAxes axes = RotationAxes.MouseXAndY;
...
为什么公共 RotationAxes 轴需要 RotationAxes?
管理员.py
from django.contrib import admin
from .models import Bd, Category
class AdminBd(admin.ModelAdmin):
list_display = ('name', 'content')
filter_horizontal = ['category', ]
admin.site.register(Bd, AdminBd)
admin.site.register(Category)
模型.py
from django.db import models
from django.urls import reverse
class Category(models.Model):
title = models.CharField(max_length=50, verbose_name='Категория')
def __str__(self):
return self.title
def get_absolute_ulr(self):
return reverse('category', kwargs={"category_id": self.pk})
class Meta:
verbose_name = 'Категория'
verbose_name_plural = 'Категории'
ordering = ['title', ]
class Bd(models.Model):
name = models.CharField(max_length=50, verbose_name='Имя')
content = models.TextField(max_length=1500, verbose_name='Именование')
category = models.ManyToManyField('Category', verbose_name='Категория')
photo = models.ImageField(upload_to='photo/%Y/%m/%d', blank=True, null=True, verbose_name='Картинка')
created_at = models.DateTimeField(auto_now_add=True, verbose_name='Дата публикации')
updated_at = models.DateTimeField(auto_now=True, verbose_name='Обновлено')
is_created = models.BooleanField(default=False, verbose_name='Создан мной')
def __str__(self):
return self.name
def get_absolute_ulr(self):
return reverse('view_news', kwargs={"news_id": self.pk})
class Meta:
verbose_name = 'Объявление'
verbose_name_plural = 'Объявления'
ordering = ['-updated_at', '-created_at']
视图.py
from django.shortcuts import render
from django.http import HttpResponse
from .models import Bd
def index(request):
bd = Bd.objects.all()
return render(request, 'news_test/index.html', {'bd': bd})
如果您删除 {'form', form} 则一切正常。
视图.py
...
def add_news(request):
if request.method == 'POST':
pass
else:
form = NewsForm()
return render(request, 'bord/add_news.html', {'form', form})
表格.py
from django import forms
from .models import Category
class NewsForm(forms.Form):
name = forms.CharField(max_length=50)
content = forms.CharField()
is_published = forms.BooleanField()
category = forms.ModelChoiceField(queryset=Category.objects.all())
add_news.html
{% extends 'base.html' %}
{% block sidebar %}
{% include 'inc/_sidebar.html' %}
{% endblock %}
{% block content %}
<h1>Добавление новости</h1>
<form action="{% url 'add_news' %}" method="post">
<button type="submit" class="btn btn-primary btn-block">Добавить новость</button>
</form>
{% endblock %}
网址.py
from django.urls import path
from .views import *
urlpatterns = [
path('', index, name='home'),
# Создание переменной category_id с типом int, это число, которое передается через url
path('category/<int:category_id>/', get_category, name='category'),
path('news/<int:news_id>/', view_news, name='view_news'),
path('news/add-news/', add_news, name='add_news')
]
学习了如何使用多线程,但无法附加多处理模块。
编码:
import requests
import multiprocessing
from bs4 import BeautifulSoup
storage_number = 100
image_num = 0
link = 'https://wallpaperscraft.ru/catalog/art/1920x1080'
link_image = 'https://images.wallpaperscraft.ru/image'
for i in range(1,storage_number):
responce = requests.get(f'{link}/page{i}').text
soup = BeautifulSoup(responce, 'lxml')
block = soup.find('ul',class_ = 'wallpapers__list')
all_image = block.find_all('li', class_ = 'wallpapers__item')
for image in all_image:
aimage_href = image.find('a').get('href')
url_image = link_image + aimage_href[9:-10] + '_1920x1080.jpg'
image_bytes = requests.get(url_image).content
with open(f'image/{image_num}.jpg', 'wb') as file:
file.write(image_bytes)
image_num += 1
试图:
import requests
from multiprocessing import Pool
from bs4 import BeautifulSoup
def multi_img():
storage_number = 2
image_num = 0
link = 'https://wallpaperscraft.ru/catalog/art/1920x1080'
link_image = 'https://images.wallpaperscraft.ru/image'
for i in range(1,storage_number):
responce = requests.get(f'{link}/page{i}').text
soup = BeautifulSoup(responce, 'lxml')
block = soup.find('ul',class_ = 'wallpapers__list')
all_image = block.find_all('li', class_ = 'wallpapers__item')
for image in all_image:
aimage_href = image.find('a').get('href')
url_image = link_image + aimage_href[9:-10] + '_1920x1080.jpg'
image_bytes = requests.get(url_image).content
with open(f'image/{image_num}.jpg', 'wb') as file:
file.write(image_bytes)
image_num += 1
with Pool(5) as p:
multi_img()
给我:
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 268, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "c:\Python_project\Request\foto_wall_new.py", line 28, in <module>
with Pool(5) as p:
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py", line 119, in Pool
return Pool(processes, initializer, initargs, maxtasksperchild,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py", line 212, in __init__
self._repopulate_pool()
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py", line 303, in _repopulate_pool
return self._repopulate_pool_static(self._ctx, self.Process,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py", line 326, in _repopulate_pool_static
w.start()
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py", line 327, in _Popen
return Popen(process_obj)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 125, in _main
prepare(preparation_data)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 268, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "c:\Python_project\Request\foto_wall_new.py", line 28, in <module>
with Pool(5) as p:
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py", line 119, in Pool
return Pool(processes, initializer, initargs, maxtasksperchild,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py", line 212, in __init__
self._repopulate_pool()
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py", line 303, in _repopulate_pool
return self._repopulate_pool_static(self._ctx, self.Process,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py", line 326, in _repopulate_pool_static
w.start()
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py", line 327, in _Popen
return Popen(process_obj)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 116, in spawn_main
Traceback (most recent call last):
File "<string>", line 1, in <module>
exitcode = _main(fd, parent_sentinel)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 125, in _main
prepare(preparation_data)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 116, in spawn_main
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 236, in prepare
exitcode = _main(fd, parent_sentinel)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 125, in _main
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
prepare(preparation_data)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 236, in prepare
main_content = runpy.run_path(main_path,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 268, in run_path
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 97, in _run_module_code
main_content = runpy.run_path(main_path,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 268, in run_path
_run_code(code, mod_globals, init_globals,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
return _run_module_code(code, init_globals, run_name,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 97, in _run_module_code
exec(code, run_globals)
File "c:\Python_project\Request\foto_wall_new.py", line 28, in <module>
_run_code(code, mod_globals, init_globals,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
with Pool(5) as p:
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py", line 119, in Pool
exec(code, run_globals)
File "c:\Python_project\Request\foto_wall_new.py", line 28, in <module>
return Pool(processes, initializer, initargs, maxtasksperchild,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py", line 212, in __init__
with Pool(5) as p:
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py", line 119, in Pool
self._repopulate_pool()
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py", line 303, in _repopulate_pool
return Pool(processes, initializer, initargs, maxtasksperchild,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py", line 212, in __init__
return self._repopulate_pool_static(self._ctx, self.Process,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py", line 326, in _repopulate_pool_static
self._repopulate_pool()
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py", line 303, in _repopulate_pool
w.start()
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\process.py", line 121, in start
return self._repopulate_pool_static(self._ctx, self.Process,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py", line 326, in _repopulate_pool_static
self._popen = self._Popen(self)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py", line 327, in _Popen
w.start()
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\process.py", line 121, in start
return Popen(process_obj)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
self._popen = self._Popen(self)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py", line 327, in _Popen
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
return Popen(process_obj)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
_check_not_importing_main()
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable. _check_not_importing_main()
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 125, in _main
prepare(preparation_data)
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "C:\Users\Владелец\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 268, in run_path
PS C:\Python_project>
虽然有效,但加速度为0
从进入和退出时间(成对):
intervals = [
{
'lesson': [1594663200, 1594666800],
'pupil': [1594663340, 1594663389, 1594663390, 1594663395, 1594663396, 1594666472],
'tutor': [1594663290, 1594663430, 1594663443, 1594666473]
}
]
有必要在字典中创建列表: 0.1 : 0.1 ; 0.1:2.3;2.3:0.1;2.3 : 2.3 ...
{
'lesson': [1594663200, 1594666800],
'pupil': [1594663340, 1594663389],
'tutor': [1594663290, 1594663430]
}
{
'lesson': [1594663200, 1594666800],
'pupil': [1594663340, 1594663389],
'tutor': [1594663443, 1594666473]
}
{
'lesson': [1594663200, 1594666800],
'pupil': [1594663390, 1594663395],
'tutor': [1594663290, 1594663430]
}
{
'lesson': [1594663200, 1594666800],
'pupil': [1594663390, 1594663395],
'tutor': [1594663443, 1594666473]
}
...
我正在编写一个应该通过所有链接 en.wikipedia.org Category:Animals_alphabetically ( https://ru.wikipedia.org/w/index.php?title=Category:Animals_alphabetically&from=А ) 的代码,但是在网站上链接不会更改数字(.../page = 1..),并且 pagefrom=Azov+button(链接取决于页面上的第一个动物)。因此,有必要走更艰难的路。
代码算法如下:
import requests
from bs4 import BeautifulSoup
def parser(url):
html = requests.get(url).text
soup = BeautifulSoup(html,'html.parser')
return soup
def parser_next_link():
soup = parser(url)
result_a = soup.find_all('a',{'title':'Категория:Животные по алфавиту'})
for i in result_a:
if i.get_text() == 'Следующая страница':
link = 'ru.wikipedia.org/' + i.get('href')
# Нам нужна, только первая ссылка т.к. вторая её дублирует
break
return link
wiki_link = ['https://ru.wikipedia.org/w/index.php?title=Категория:Животные_по_алфавиту&subcatfrom=0&filefrom=0&pageuntil=Азовская+пуголовка#mw-pages']
for i in wiki_link:
url = i
wiki_link.append(parser_next_link())
# Последняя страница
if url == 'https://ru.wikipedia.org/w/index.php?title=Категория:Животные_по_алфавиту&pagefrom=Zabrus&subcatfrom=0&filefrom=0#mw-pages':
break
输出:
Traceback (most recent call last):
File "c:\Project_Py\test_2.py", line 26, in <module>
wiki_link.append(parser_next_link())
File "c:\Project_Py\test_2.py", line 12, in parser_next_link
soup = parser(url)
File "c:\Project_Py\test_2.py", line 6, in parser
html = requests.get(url).text
File "C:\Users\Владелец\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\Владелец\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\Владелец\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Владелец\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\sessions.py", line 649, in send
adapter = self.get_adapter(url=request.url)
File "C:\Users\Владелец\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\sessions.py", line 742, in get_adapter
raise InvalidSchema("No connection adapters were found for {!r}".format(url))
requests.exceptions.InvalidSchema: No connection adapters were found for 'ru.wikipedia.org//w/index.php?title=%D0%9A%D0%B0%D1%82%D0%B5%D0%B3%D0%BE%D1%80%D0%B8%D1%8F:%D0%96%D0%B8%D0%B2%D0%BE%D1%82%D0%BD%D1%8B%D0%B5_%D0%BF%D0%BE_%D0%B0%D0%BB%D1%84%D0%B0%D0%B2%D0%B8%D1%82%D1%83&pagefrom=%D0%90%D0%B7%D0%BE%D0%B2%D1%81%D0%BA%D0%B0%D1%8F+%D0%BF%D1%83%D0%B3%D0%BE%D0%BB%D0%BE%D0%B2%D0%BA%D0%B0&subcatfrom=%D0%90&filefrom=%D0%90#mw-pages'
PS C:\Project_Py> & C:/Users/Владелец/AppData/Local/Microsoft/WindowsApps/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/python.exe c:/Project_Py/test_2.py
Traceback (most recent call last):
File "c:\Project_Py\test_2.py", line 26, in <module>
wiki_link.append(parser_next_link())
File "c:\Project_Py\test_2.py", line 12, in parser_next_link
soup = parser(url)
resp = self.send(prep, **send_kwargs)
File "C:\Users\Владелец\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\sessions.py", line 649, in sendbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\sessions.py", line 649, in send bz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\sessions.py", line 742, in get_adapter
adapter = self.get_adapter(url=request.url)
File "C:\Users\Владелец\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_q.org//w/index.php?title=%D0%9A%D0%B0%D1%82%D0%B5%D0%B3%D0%BE%D1%80%D0%B8%D1%8F:%D0%96%D0%B8%D0%B2%D0%BE%D1%82%D0%BD%D1%8bz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\requests\sessions.py", lD0%B7%D0%BE%D0%B2%D1%81%D0%BA%D0%B0%D1%8F+%D0%BF%D1%83%D0%B3%D0%BE%D0%BB%D0%BE%D0%B2%D0%BA%D0%B0&subcatfrom=%D0%90&filefine 742, in get_adapter
raise InvalidSchema("No connection adapters were found for {!r}".format(url))
requests.exceptions.InvalidSchema: No connection adapters were found for 'ru.wikipedia.org//w/index.php?title=%D0%9A%D0%B0%D1%82%D0%B5%D0%B3%D0%BE%D1%80%D0%B8%D1%8F:%D0%96%D0%B8%D0%B2%D0%BE%D1%82%D0%BD%D1%8B%D0%B5_%D0%BF%D0%BE_%D0%B0%D0%BB%D1%84%D0%B0%D0%B2%D0%B8%D1%82%D1%83&pagefrom=%D0%90%D0%B7%D0%BE%D0%B2%D1%81%D0%BA%D0%B0%D1%8F+%D0%BF%D1%83%D0%B3%D0%BE%D0%BB%D0%BE%D0%B2%D0%BA%D0%B0&subcatfrom=%D0%90&filefrom=%D0%90#mw-pages'
我意识到错误是递归的,但我也有一个停止条件。
fmtText = "Lorem ipsum dolor! diam amet, consetetur Lorem magna. sed diam nonumy eirmod tempor. diam et labore? et diam magna. et diam amet."
freqMap = {}
wordList = fmtText.split(' ')
for word in set(wordList):
freqMap.update({word:fmtText.count(word)})
print(freqMap)
{'amet.': 1, 'nonumy': 1, 'consetetur': 1, 'magna.': 2, 'diam': 5, 'sed': 1, 'labore?': 1, 'dolor!' : 1, 'tempor.': 1, 'Lorem': 2, 'eirmod': 1, 'amet,': 1, 'ipsum': 1, 'et': 7}
fmtText = "Lorem ipsum dolor! diam amet, consetetur Lorem magna. sed diam nonumy eirmod tempor. diam et labore? et diam magna. et diam amet."
# split text into words
wordList = fmtText.split(' ')
# Create dictionary
freqMap = {}
for word in set(wordList): # use set to remove duplicates in list
freqMap[word] = wordList.count(word)
print(freqMap)
{'amet.': 1, 'nonumy': 1, 'consetetur': 1, 'magna.': 2, 'diam': 5, 'sed': 1, 'labore?': 1, 'dolor!' : 1, 'tempor.': 1, 'Lorem': 2, 'eirmod': 1, 'amet,': 1, 'ipsum': 1, 'et': 3}
我不明白为什么 et = 3,在第一种情况下,在第二种情况下 et = 7(第二个是整个文本中 et 的数量,在第一个 et 单词中)